pandas agg rename columns
df.groupby(lambda _ : True).agg(new_col_name = ('col_name', 'agg_function'))
4
4
grouped = df.groupby('id').agg({'col1': [('name1', 'sum')], 'col2': [('name2_mean', 'sum'), ('name2_custom_std', lambda x: np.std(x))]})
grouped.columns = grouped.columns.droplevel()
Thank you!
4
0
Are there any code examples left?
New code examples in category Python