How Can I Aggregate (sum, Mean, Etc.) Values And Create A New Pandas Dataframe Based On That?
I have a Pandas dataframe that has multiple date columns. Year Month Count1 Count2 2015-01-01 2015-05-01 11
Solution 1:
This operation can be done by;
agg_col = "Year"new_df = df.groupby(by=agg_col, as_index=False).agg({"Count1": "sum", "Count2": "sum"})
And you can change agg_col
to Month
if you want to group by month.
Post a Comment for "How Can I Aggregate (sum, Mean, Etc.) Values And Create A New Pandas Dataframe Based On That?"