pandas/groupby

Group By

Group DataFrame using one or more columns

pandas
groupby
aggregation

Command

df.groupby

Explanation

df.groupby() is used to group data and apply aggregation functions.

Examples

Group by column and calculate mean

df.groupby("col1").mean()

Group by multiple columns and sum

df.groupby(["col1", "col2"]).sum()