我正在尝试使用pandas DataFrame的pivot_table方法;
mean_ratings = data.pivot_table('rating', rows='title', cols='gender', aggfunc='mean')
但是,我收到以下错误:
---------------------------------------------------------------------------
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'
以上命令取自Wes McKinney(熊猫的创造者)的书“Python for Data Analysis”
答案 0 :(得分:32)
我的解决方案是更改'rows =&gt; index'和'cols =&gt; columns'):
自:
mean_ratings = data.pivot_table('rating', rows='title', cols='gender', aggfunc='mean')
为:
mean_ratings = data.pivot_table('rating', index='title', columns='gender', aggfunc='mean')