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

qt - QML MouseArea onWheel event not working properly when inside QML Scrollview -

java - is not an enclosing class / new Intent Cannot Resolve Constructor -

python - Error importing VideoFileClip from moviepy : AttributeError: 'PermissionError' object has no attribute 'message' -