I have a pandas data frame I want to count how often a number appears in a column for each column
a b c d e
0 2 3 1 5 4
1 1 3
You can do:
(df==1).sum()
df==1
gives:
a b c d e
0 False False True False False
1 True False False False False
2 True False False False False
3 False False True False False
4 False False True False False
and the sum()
treats False
as 0
and True
as 1
.
This should do the trick
df1[df1 == 1].count()