python - Pandas Groupby - naming aggregate output column -


i have pandas groupby command looks this:

df.groupby(['year', 'month'], as_index=false).agg({'users':sum}) 

is there way can name agg output other 'users' during groupby command? example, if wanted sum of users total_users? rename column after groupby complete, wonder if there way.

per docs:

if dict passed, keys used name columns. otherwise function’s name (stored in function object) used.

in [58]: grouped['d'].agg({'result1' : np.sum, ....:
'result2' : np.mean})

in case:

df.groupby(['year', 'month'], as_index=false).users.agg({'total_users': np.sum}) 

Comments