标签:xls groupby agg tab col val das data include
import pandas as pd
pivot_data=pd.read_excel(‘./data/data3.xlsx‘)
pivot_data.head()
pivot_data.describe(include=‘all‘).T
import numpy as np
#透视表 求进货价合计、平均值 、计数
# print(df2.col())
rst1=pivot_data.pivot_table(index=[‘供应商名称‘],values=[‘销售价‘],aggfunc=np.sum)
print(rst1)
# ret2=pivot_data.groupby(‘供应商名称‘)[‘销售价‘].sum() #与上面效果相同
# print(rst2)
rst2=pivot_data.pivot_table(index=[‘供应商名称‘],values=[‘销售价‘],aggfunc=np.mean)
rst2.head()
rst3=pivot_data.pivot_table(index=[‘供应商名称‘],values=[‘销售价‘],aggfunc=np.count_nonzero)
rst3.head()
rst4=pivot_data.pivot_table(index=[‘供应商名称‘],values=[‘销售价‘,‘供应商进货价‘],aggfunc={‘销售价‘:np.sum,‘供应商进货价‘:np.mean})
rst4.head()
标签:xls groupby agg tab col val das data include
原文地址:https://www.cnblogs.com/tiankong-blue/p/11620692.html