[英]pandas pivot_table multiple aggfunc
When I create a pivot table on a dataframe I have, passing aggfunc='mean'
works as expected, aggfunc='count'
works as expected, however aggfunc=['mean', 'count']
results in: AttributeError: 'str' object has no attribute '__name__
当我在数据帧上创建数据透视表时,传递
aggfunc='mean'
按预期工作, aggfunc='count'
按预期工作,但aggfunc=['mean', 'count']
导致: AttributeError: 'str' object has no attribute '__name__
This format seemed to work previously: Multiple AggFun in Pandas 这种格式似乎先前有效: Pandas中的多个AggFun
How do I create a pivot table with multiple functions? 如何创建具有多个功能的数据透视表?
我发现如果你只是用普通的方括号代替方括号,那就行了
aggfunc=('count','mean')
An example: 一个例子:
In [59]: pivot_table(tips, rows=['sex', 'smoker'],
aggfunc={'tip_pct' : 'mean', 'size' : 'sum'})
Out[59]:
size tip_pct
sex smoker
Female No 140 0.1569
Yes 74 0.1822
Male No 263 0.1607
Yes 150 0.1528
Source: http://wesmckinney.com/blog/fast-and-easy-pivot-tables-in-pandas-0-5-0/ 资料来源: http : //wesmckinney.com/blog/fast-and-easy-pivot-tables-in-pandas-0-5-0/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.