I have a dataframe df
which looks like the following:
num1 | num2 | bool1 | bool2 | bool3 |
---|---|---|---|---|
20 | 30 | True | False | True |
10 | 5 | False | True | True |
For each row I want to count the number of True
values for a specific subset of the boolean columns, say bool2
and bool3
. So the desired output would look like this:
num1 | num2 | bool1 | bool2 | bool3 | count |
---|---|---|---|---|---|
20 | 30 | True | False | True | 1 |
10 | 5 | False | True | True | 2 |
In SQL I used to do this with something like CARDINALITY(bool2, bool3). Trying to figure out if there is a simple way to do something like that in Pandas.