I want to apply multiple functions of multiple columns to a groupby object which results in a new pandas.DataFrame.
I know how to do it in seperate steps:
by_user = lasts.groupby('user')
elapsed_days = by_user.apply(lambda x: (x.elapsed_time * x.num_cores).sum() / 86400)
running_days = by_user.apply(lambda x: (x.running_time * x.num_cores).sum() / 86400)
user_df = elapsed_days.to_frame('elapsed_days').join(running_days.to_frame('running_days'))
Which results in user_df being:

However I suspect that there is a better way, like:
by_user.agg({'elapsed_days': lambda x: (x.elapsed_time * x.num_cores).sum() / 86400, 
             'running_days': lambda x: (x.running_time * x.num_cores).sum() / 86400})
However, this doesn't work, because AFAIK agg() works on pandas.Series.
I did find this question and answer, but the solutions look rather ugly to me, and considering that the answer is nearly four years old, there might be a better way by now.
 
     
     
     
     
     
     
    