2

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 )

Ryan Kapsak
  • 111
  • 5
  • 2
    Does this answer your question? [Count the frequency that a value occurs in a dataframe column](https://stackoverflow.com/questions/22391433/count-the-frequency-that-a-value-occurs-in-a-dataframe-column) – Manpreet Singh Sep 14 '21 at 14:22
  • There we go. Thanks! I `used:df['genus'].value_counts()` – Ryan Kapsak Sep 14 '21 at 14:29

1 Answers1

2

This should work,

df['genus'].value_counts()

or

df.genus.value_counts()