Python Pandas - Groupby and Mean, but keep column name -


i trying find mean of column each unique value in column, , using code:

a_df = b.groupby('r')['l'].mean 

and mean value each value in 'r', mean values has no column name, cant sort on it.

is there way of doing above does, give mean values column name can sort on it?

thank you

use parameter as_index=false or reset_index:

a_df = b.groupby('r', as_index=false)['l'].mean() 

or:

a_df = b.groupby('r')['l'].mean().reset_index() 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -