分组统计
1.创建分组
g = df.groupby('color')
2.显示分组内容

3.分组对象的统计方法
分组对象的属性和方法
直接执行describe()操作
g.列名.describe()

或者用g.agg()传递多个指定的统计函数
4.数据透视表
数据透视表功能类似于Excel中的数据透视表功能
df.pivot_table(index='color', columns='size',values='quantity', aggfunc= 'sum') #index分组索引列,colums列名,values计算的列,aggfunc计算方法

网友评论