Reputation: 31908
I have a dataframe, like the following:
True True
False True
I would like to count the number of True
values for each row, something like
df.count(value=True, axis=1)
or
df.apply(count(False), axis=1)
It should return 2 1
.
How do I do that?
Upvotes: 1
Views: 50
Reputation: 249143
You can do it like this:
df.sum(axis=1)
This relies on the fact that True
is counted as 1 and False
as 0, and is optimally efficient.
Upvotes: 2