Skip to main content

sum()

df.groupby(column_name).sum()

Returns a DataFrame, with rows as groups, and each column as the sum of the column values within each group.

Note:
Only for columns of type int or float, all other columns are automatically dropped.

pets
IndexSpeciesColorWeightAge
0dogblack405
1catgolden158
2catblack209
3dogwhite802
4dogblack250.5
5hamsterblack13
6hamstergolden0.250.2
pets.groupby('Species').sum()
IndexWeightAgeIs_Cat
cat26.59.23
dog1457.50
hamster1.253.20