TypeError: pivot_table() got an unexpected keyword argument 'rows'

来源:互联网 发布:幽浮2知乎 编辑:程序博客网 时间:2024/05/21 00:48

利用Python进行数据分析》第二章,处理MovieLens 1M数据集,有句代码总是报错:

mean_rating = data.pivot_table('rating', rows='title', cols='gender', aggfunc='mean')

报错信息如下:

Traceback (most recent call last):  File "D:\Users\wangshuang829\AppData\Local\Continuum\Anaconda\lib\site-packages\IPython\core\interactiveshell.py", line 3035, in run_code    exec(code_obj, self.user_global_ns, self.user_ns)  File "<ipython-input-47-d6e7435a4a95>", line 1, in <module>    mean_rating = data.pivot_table('rating', rows='title', cols='gender', aggfunc='mean')TypeError: pivot_table() got an unexpected keyword argument 'rows'

修改办法:rows改成index,cols写成全名”columns”

mean_rating = data.pivot_table('rating', index='title', columns='gender', aggfunc='mean')

修改后得到正确处理结果:

gender                                F         Mtitle                                            $1,000,000 Duck (1971)         3.375000  2.761905'Night Mother (1986)           3.388889  3.352941'Til There Was You (1997)      2.675676  2.733333'burbs, The (1989)             2.793478  2.962085...And Justice for All (1979)  3.828571  3.689024
阅读全文
1 0
原创粉丝点击