概述
学习地址:https://tianchi.aliyun.com/s/58327c15d1faee512c008128d3bb9e32
学习内容:宝可梦数据分析
问题:pip不能用,还在研究如何安装包
总结:编程基础知识需要加强,pandas和seaborn等包没有系统学习过,学习过程比较吃力。
口袋妖怪数据集探索
CSV文件:Comma-Separated Values,中文叫,逗号分隔值或者字符分割值,其文件以纯文本的形式存储表格数据。
1. 读取数据
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
df = pd.read_csv("./pokemon_data.csv")
2. 缺值分析
# 计算出每个特征有多少百分比是缺失的
percent_missing = df.isnull().sum() * 100 / len(df)
missing_value_df = pd.DataFrame({
'column_name': df.columns,
'percent_missing': percent_missing
})
# 查看Top10缺失的
missing_value_df.sort_values(by='percent_missing', ascending=False).head(10)
3. 查看分布
# 查看各代口袋妖怪的数量
df['generation'].value_counts().plot.bar()
# 查看每个系口袋妖怪的数量
df['type1'].value_counts().sort_values(ascending=True).plot.barh()
4. 相关分析
# 相关性热力图分析
plt.subplots(figsize=(20,15))
ax = plt.axes()
ax.set_title("Correlation Heatmap")
corr = df.corr()
sns.heatmap(corr,
xticklabels=corr.columns.values,
yticklabels=corr.columns.values)
interested = ['hp','attack','defense','sp_attack','sp_defense','speed']
sns.pairplot(df[interested])
# 通过相关性分析heatmap分析五个基础属性
plt.subplots(figsize=(10,8))
ax = plt.axes()
ax.set_title("Correlation Heatmap")
corr = df[interested].corr()
sns.heatmap(corr,
xticklabels=corr.columns.values,
yticklabels=corr.columns.values,
annot=True, fmt="f",cmap="YlGnBu")
<AxesSubplot:title={
'center':'Correlation Heatmap'}>
for c in interested:
df[c] = df[c].astype(float)
df = df.assign(total_stats = df[interested].sum(axis=1))
df[df.total_stats >= 525].shape
(167, 42)
- 种族值分布
for c in interested:
df[c] = df[c].astype(float)
df = df.assign(total_stats = df[interested].sum(axis=1))
# 种族值分布
total_stats = df.total_stats
plt.hist(total_stats,bins=35)
plt.xlabel('total_stats')
plt.ylabel('Frequency')
plt.show()
# 不同属性的种族值分布
plt.subplots(figsize=(20,12))
ax = sns.violinplot(x="type1", y="total_stats",
data=df, palette="muted")
plt.show()
df[(df.total_stats >= 570) & (df.is_legendary == 0)]['name'].head(10)