for given data i need to find the count of "a" in the column Key

Viewed 18
     Key
----------
0     a
1     a
2     b
3     b
4     a
5     c

so far i tried this:

df.groupby(["key1"],).count()

However it is also showing the counts of b and c, i want only for a.

1 Answers

Create mask and count by sum:

df["Key"].eq('a').sum()
Related