Set column name for apply result over groupby

You could convert your series to a dataframe using reset_index() and provide name="yout_col_name" — The name of the column corresponding to the Series values

(df_grp.apply(lambda x: x['C'].sum() * x['D'].mean() / x['E'].max())

   A  B  your_col_name
0  X  N   5.583333
1  Y  M   2.975000
2  Y  N   3.845455

Leave a Comment