count()
df.groupby(column_name).count()
Returns a DataFrame, with rows as groups, and all columns as the number of rows in each group.
- Note:
- All columns have the same value. It is advised to drop and rename the columns.
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').count()
Index | ID | Color | Weight | Age |
---|---|---|---|---|
cat | 2 | 2 | 2 | 2 |
dog | 3 | 3 | 3 | 3 |
hamster | 2 | 2 | 2 | 2 |