Skip to content

Instantly share code, notes, and snippets.

@mprzybyla123
Created June 7, 2021 16:55
Show Gist options
  • Save mprzybyla123/f1978d6f95612464a16d5c0caf3a42c3 to your computer and use it in GitHub Desktop.
Save mprzybyla123/f1978d6f95612464a16d5c0caf3a42c3 to your computer and use it in GitHub Desktop.
aggregation
# what columns you want to group by
cols = ['Day', 'Ocean']
# picking the aggregation type ex: 'mean'
group = df_example.groupby(cols).agg({
'1': ['mean'],
'2: ['mean']})
# rename the column names with their respective aggregation type
group.columns = ["_".join(x) for x in group.columns.ravel()]
# look at the groupings
group.head()
# see how it looks on the original dataframe level
grouped_df = group.reset_index()
grouped_df.head()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment