mean()
df.groupby(column_name).mean()
Returns a DataFrame, with rows as groups, and each column as the mean of the column values within each group.
- Note:
- Only for columns of type
int
orfloat
, all other columns are automatically dropped.
pets
Index | Species | Color | Weight | Age |
---|---|---|---|---|
0 | dog | black | 40 | 5 |
1 | cat | golden | 15 | 8 |
2 | cat | black | 20 | 9 |
3 | dog | white | 80 | 2 |
4 | dog | black | 25 | 0.5 |
5 | hamster | black | 1 | 3 |
6 | hamster | golden | 0.25 | 0.2 |
pets.groupby('Species').mean()
Index | Weight | Age | Is_Cat |
---|---|---|---|
cat | 8.8333333333 | 3.0666666667 | 1 |
dog | 48.3333333333 | 2.5 | 0 |
hamster | 0.625 | 1.6 | 0 |