-
-
Save mprzybyla123/f1978d6f95612464a16d5c0caf3a42c3 to your computer and use it in GitHub Desktop.
aggregation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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