Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

I'm trying to use the pivot_table method of a pandas DataFrame;

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)

like image 937
Chris Snow Avatar asked Feb 10 '16 14:02

Chris Snow


1 Answers

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') 
like image 193
Chris Snow Avatar answered Sep 27 '22 23:09

Chris Snow