-
学习链接:
https://tianchi.aliyun.com/s/58327c15d1faee512c008128d3bb9e32 -
今日学习任务:
Task 4:宝可梦数据分析! -
记录笔记:
学习完成之后,选择任意平台进行自我知识总结即可(今天学到了什么将来可能需要复习的知识点,用笔记来方便自己复习)知乎、CSDN、Github等。(如果对记笔记有疑惑,欢迎讨论)
Pandas, Seaborn, Matplotlib库 安装
pip install matplotlib -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
pip install seaborn -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
pip install pandas -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
读取数据
df.info() 能够给我们更加详细的每个列的信息
# -*- coding: utf-8 -*-
#宝可梦数据分析-平民最强宝可梦系列
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
df = pd.read_csv("pokemon.csv")
df.info()
计算出每个特征有多少百分比是缺失的
# -*- coding: utf-8 -*-
#宝可梦数据分析-平民最强宝可梦系列
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
df = pd.read_csv("pokemon.csv")
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)
plt.show()
查看各代口袋妖怪的数量
# -*- coding: utf-8 -*-
#宝可梦数据分析-平民最强宝可梦系列
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
df = pd.read_csv("pokemon.csv")
df['generation'].value_counts().plot.bar()
plt.show()
plt.show()
查看每个系口袋妖怪的数量
# -*- coding: utf-8 -*-
#宝可梦数据分析-平民最强宝可梦系列
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
df = pd.read_csv("pokemon.csv")
df['type1'].value_counts().sort_values(ascending=True).plot.barh()
plt.show()
plt.show()
从宝可梦在实战中的角度来分析这组数据
# -*- coding: utf-8 -*-
#宝可梦数据分析-平民最强宝可梦系列
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
df = pd.read_csv("pokemon.csv")
#从宝可梦在实战中的角度来分析这组数据
interested = ['hp','attack','defense','sp_attack','sp_defense','speed']
sns.pairplot(df[interested])
plt.show()
plt.show()
通过相关性分析heatmap分析五个基础属性
# -*- coding: utf-8 -*-
#宝可梦数据分析-平民最强宝可梦系列
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
df = pd.read_csv("pokemon.csv")
# 通过相关性分析heatmap分析五个基础属性
interested = ['hp','attack','defense','sp_attack','sp_defense','speed']
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")
plt.show()
种族值分布
# -*- coding: utf-8 -*-
#宝可梦数据分析-平民最强宝可梦系列
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
df = pd.read_csv("pokemon.csv")
#选取平民神兽
interested = ['hp','attack','defense','sp_attack','sp_defense','speed']
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()
不同属性的种族值分布
# -*- coding: utf-8 -*-
#宝可梦数据分析-平民最强宝可梦系列
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
df = pd.read_csv("pokemon.csv")
#选取平民神兽
interested = ['hp','attack','defense','sp_attack','sp_defense','speed']
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.subplots(figsize=(20,12))
ax = sns.violinplot(x="type1", y="total_stats",
data=df, palette="muted")
plt.show()
找到神兽
# -*- coding: utf-8 -*-
#宝可梦数据分析-平民最强宝可梦系列
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
df = pd.read_csv("pokemon.csv")
interested = ['hp','attack','defense','sp_attack','sp_defense','speed']
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
#找到神兽
df[(df.total_stats >= 570) & (df.is_legendary == 0)]['name'].head(10)
plt.show()
效果没调试出来,一脸蒙蔽!