2016-02-10 14 views
16

Sto provando ad utilizzare il metodo pivot_table di un DataFrame panda;TypeError: pivot_table() ha ottenuto un argomento parola chiave inaspettato 'rows'

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

Tuttavia, ricevo il seguente errore:

--------------------------------------------------------------------------- 
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' 

Il comando precedente è stata presa dal libro 'Python for Data Analysis' da Wes McKinney (il creatore di panda)

risposta

23

La soluzione per me doveva cambiare 'rows => index' e 'cols => columns'):

Da:

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

a:

mean_ratings = data.pivot_table('rating', index='title', columns='gender', aggfunc='mean') 
+1

In realtà non è una soluzione, solo la sintassi corretta per 'pivot_table' ... –

+0

Suona come un insetto nel libro che ho copiato il comando da. Ho aggiornato la domanda per riflettere questo. –

+2

No, non è un bug, queste sono solo le vecchie parole chiave che sono state deprecate per un po 'e ora rimosse. Da qui l'errore che hai ottenuto – joris

Problemi correlati