median()
df.groupby(column_name).median()
Returns a DataFrame, with rows as groups, and each column as the median 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').median()
Index | Weight | Age | Is_Cat |
---|---|---|---|
cat | 10 | 0.2 | 1 |
dog | 40 | 2 | 0 |
hamster | 0.625 | 1.6 | 0 |