Answers for "pandas agg rename columns"

0

how can i aggregate without group by in pandas

df.groupby(lambda _ : True).agg(new_col_name = ('col_name', 'agg_function'))
Posted by: Guest on July-27-2020
0

pandas agg rename columns

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()
Posted by: Guest on August-10-2021

Python Answers by Framework

Browse Popular Code Answers by Language