Reputation: 47
For example, I have a dataframe A likes below :
a b c
x 0 2 1
y 1 3 2
z 0 2 4
I want to get the number of 0 in column 'a' , which should returns 2. ( A[x][a] and A[z][a] )
Is there a simple way or is there a function I can easily do this?
I've Googled for it, but there are only articles like this.
count the frequency that a value occurs in a dataframe column
Which makes a new dataframe, and is too complicated to what I only need to do.
Upvotes: 1
Views: 90
Reputation: 862601
Use sum
with boolean mask - True
s are processes like 1
, so output is count of 0
values:
out = A.a.eq(0).sum()
print (out)
2
Upvotes: 2