How to sum # of rows of a column containing a categorical variable in Python

Viewed 129

Let's say my data frame has a column 'genus', and it contains 5 rows each that contain 'seed', 'flame', 'turtle', and 'shellfish'.

How can you get Python to add up each category and print out a total count for each category? I want to be able to apply a function that will automatically do this for each unique category in the column 'genus' without having to go and parse out each unique category.

I would want to see something like: seed: 5 flame: 5 turtle: 5 Shellfish: 5

(yes, this is a Pokemon dataset )

1 Answers

This should work,

df['genus'].value_counts()

or

df.genus.value_counts()
Related