count values by name in pandas dataframe

Viewed 116

How to count number of values by their name? I have a pandas data frame:

word token 
physical I-Problem 
design I-Problem 
for I-Problem 
XML I-Problem 
databases I-Problem 
which o 
is o 
the o 
process o 

I need to count how many I-Problem in the token. I tried df['token'].count('I-Problem') but it doesn't work.

expected output :

I-Problem : 5

or

5
1 Answers

Use value_counts:

>>> df['token'].value_counts()['I-Problem']
5
>>> 

Or try tolist:

>>> df['token'].tolist().count('I-Problem')
5
>>> 
Related