pd.pivot_table聚合计算注意事项

参数 类型 说明
data DataFrame pd.pivot_table使用,设定需要操作的 DataFrame
values column

被计算的数据项

可选项

设定需要被聚合操作的列

index

array

column

grouper

list of the previous

行分组键

用于分组的列名或其他分组键,作为结果DataFrame的行索引

Keys to group by on the pivot table index

columns

array

column

grouper

list of the previous

列分组键

用于分组的列名或其他分组键,作为结果DataFrame的列索引

Keys to group by on the pivot table column

aggfunc

dict 

function

list of functions

numpy.mean 默认值

聚合函数或函数列表

如果aggfunc中出现list [ ],则在结果DataFrame中,list 内的函数名称肯定会出现在 columns中

  • aggfunc = np.sum
  • ☑ aggfunc = [ np.sum ]
  • aggfunc = [ np.sum,np.mean ] 
  • aggfunc = { 'Price':np.sum } 
  • aggfunc = { 'Price':[np.sum] } 
  • aggfunc = { 'Price':np.sum,'Quantity':len }
  • aggfunc = { 'Price':[np.sum],'Quantity':len }
  • aggfunc = { 'Price':[np.sum,np.mean],'Quantity':len }
  • ☑ 出现 ☒ 不出现

posted on 2020-08-14 17:47  上山打老虎下山采蘑菇  阅读(625)  评论(0编辑  收藏  举报

导航