分組分析是指根據(jù)字段分組,將分析對象劃分成不同的部分,以進行對比分析各組之間的差異性的一種分析方法。
常用的統(tǒng)計指標(biāo):計數(shù)、求和、平均值
分組統(tǒng)計函數(shù):
groupby(by=[分組列1,分組列2,...])[統(tǒng)計列1,統(tǒng)計列2,...].agg({統(tǒng)計列別名1:統(tǒng)計函數(shù)1,統(tǒng)計列別名2:統(tǒng)計函數(shù)2,...})
參數(shù)說明:
by:用于分組的列
中括號:用于統(tǒng)計的列
agg:統(tǒng)計別名顯示統(tǒng)計值的名稱,統(tǒng)計函數(shù)用于統(tǒng)計數(shù)據(jù)
常用統(tǒng)計函數(shù):size計數(shù),sum求和,mean均值
但是當(dāng)我使用這個函數(shù)時,系統(tǒng)報錯
FutureWarning: using a dict on a Series for aggregation is deprecated and will be removed in a future version
或者
FutureWarning: using a dict with renaming is deprecated and will be removed in a future version return super(DataFrameGroupBy, self).aggregate(arg, *args, **kwargs)
這是由于Python升級不再使用這個函數(shù)語法了。
經(jīng)修改

PyCharm
正常運行。
原始數(shù)據(jù)

data
分組統(tǒng)計后:

aggResult