pandas 类型错误:pivot_table() 得到了一个意外的关键字参数“行”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35318269/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
TypeError: pivot_table() got an unexpected keyword argument 'rows'
提问by Chris Snow
I'm trying to use the pivot_table method of a pandas DataFrame;
我正在尝试使用 Pandas DataFrame 的 pivot_table 方法;
mean_ratings = data.pivot_table('rating', rows='title', cols='gender', aggfunc='mean')
However, I receive the following error:
但是,我收到以下错误:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-55-cb4d494f2f39> in <module>()
----> 1 mean_ratings = data.pivot_table('rating', rows='title', cols='gender', aggfunc='mean')
TypeError: pivot_table() got an unexpected keyword argument 'rows'
The above command was taken from the book 'Python for Data Analysis' by Wes McKinney (the creator of pandas)
上述命令取自Wes McKinney(pandas 的创建者)的《Python for Data Analysis》一书
回答by Chris Snow
The solution for me was to change 'rows=>index' and 'cols=>columns'):
我的解决方案是更改“行=>索引”和“列=>列”):
From:
从:
mean_ratings = data.pivot_table('rating', rows='title', cols='gender', aggfunc='mean')
to:
到:
mean_ratings = data.pivot_table('rating', index='title', columns='gender', aggfunc='mean')