datawhale数据分析学习day06

day06:数据聚合与运算、数据可视化

 

*GroupBy机制是什么:"Split - Apply - Combine"
Splitting: 将数据按需求分组;
Applying: 对每个小组进行函数操作;
Combining: 合并结果。

详细解说链接:https://blog.csdn.net/weixin_31659249/article/details/112502995

*agg()函数是什么:

agg()函数是聚合函数,DataFrame.agg(func,axis = 0,* args,** kwargs )
@@@func : 实现某种统计功能的函数,如果要不同列用求不同统计量,则用字典{‘行名/列名’,‘函数名’}指定。

详细回答链接:https://blog.csdn.net/weixin_38168620/article/details/82149197

*平均(票价):

df  = text['Fare'].groupby(text['Sex'])
means = df.mean()

*总和(不同性别生存总和):

survived_sex = text['Survived'].groupby(text['Sex']).sum()
survived_sex.head()

*总和(不同等级生存总和)

survived_pclass = text['Survived'].groupby(text['Pclass'])
survived_pclass.sum()

*平均(不同等级的票不同年龄的船票费用平均值)

text.groupby(['Pclass','Age'])['Fare'].mean().head()

*比率(不同年龄中最高的存活年龄的最高的存活率)

#不同年龄的存活人数
survived_age = text['Survived'].groupby(text['Age']).sum()
survived_age.head()

#找出最大值的年龄段
survived_age[survived_age.values==survived_age.max()]
_sum = text['Survived'].sum()

#首先计算总人数
_sum = text['Survived'].sum()
print("sum of person:"+str(_sum))
precetn =survived_age.max()/_sum
print("最大存活率:"+str(precetn))

*matplotlib库的用法:

详细回答链接:https://blog.csdn.net/gdkyxy2013/article/details/80294021

*柱状图可视化案例(男女中生存人数分布情况)

sex = text.groupby('Sex')['Survived'].sum()
sex.plot.bar()
plt.title('survived_count')
plt.show()

*柱状图可视化案例(男女中生存人与死亡人数的比例图)

text.groupby(['Sex','Survived'])['Survived'].count().unstack().plot(kind='bar',stacked='True')
plt.title('survived_count')
plt.ylabel('count')

*折线图可视化案例(不同票价的人生存和死亡分布情况)

fig = plt.figure(figsize=(20, 18))
fare_sur.plot(grid=True)
plt.legend()
plt.show()

*柱状图可视化案例(不同仓位等级的人生存和死亡人员分布情况)

pclass_sur = text.groupby(['Pclass'])['Survived'].value_counts()
import seaborn as sns
sns.countplot(x="Pclass", hue="Survived", data=text)

*折线图可视化案例(不同年龄的人生存与死亡人数分布情况)

facet = sns.FacetGrid(text, hue="Survived",aspect=3)
facet.map(sns.kdeplot,'Age',shade= True)
facet.set(xlim=(0, text['Age'].max()))
facet.add_legend()

*折线图可视化案例(不同仓位等级的人年龄分布情况)

text.Age[text.Pclass == 1].plot(kind='kde')
text.Age[text.Pclass == 2].plot(kind='kde')
text.Age[text.Pclass == 3].plot(kind='kde')
plt.xlabel("age")
plt.legend((1,2,3),loc="best")

*其他可视化模块,如:pyecharts,bokeh等

pyecharts:pyecharts 是一个用于生成 Echarts 图表的类库。Echarts 是百度开源的一个数据可视化 JS 库。用 Echarts 生成的图可视化效果非常棒,为了与 Python 进行对接,方便在 Python 中直接使用数据生成图。

详细可参考链接:https://blog.csdn.net/qq_43273590/article/details/87889882

bokeh:一款针对现代Web浏览器呈现功能的交互式可视化库

详细可参考链接:https://zhuanlan.zhihu.com/p/35182438

 

本次的学习基于datawhale学习打卡小组:

链接:https://github.com/datawhalechina/hands-on-data-analysis

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值