1

This should be a really easy one, but I can't figure it out:: I have a dataframe, df, and it has two string values, "normal" and "odd". I'd like to find out how many are in either catagory::

type(bro_df)
pandas.core.frame.DataFrame

print(len(bro_df))
2000000

type(bro_df['label'])
pandas.core.series.Series

print(len(bro_df['label'] == 'normal'))
2000000

print(len(bro_df['label'] == 'odd'))
2000000

What's going on??!?!

Thanks, Nic

0

1 Answer 1

2

len(bro_df['label'] == 'odd') is the length of the boolean series of True and False. If you want the number of rows with those values:

(bro_df['label'] == 'odd').sum()

Or better yet

bro_df.label.value_counts()
Sign up to request clarification or add additional context in comments.

1 Comment

Yeah, these both work a treat, and can be applied to my/ones given circumstances. :-) Thanks!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.