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 😂)

2

1 Answer 1

2

This should work,

df['genus'].value_counts()

or

df.genus.value_counts()
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.