Reputation: 1309
How can I quickly drop rows where A, B and C are all false? I tried:
df3 = df[~(~(df['A'])& ~(df['B']) & ~(df['C']) )]
df3
com A B C
0 as TRUE FALSE FALSE
1 da TRUE FALSE FALSE
Upvotes: 3
Views: 344
Reputation: 18647
An alternative using all
along axis 1. The 2nd ~
operator directly - directly before df
, reversed all False
to True
. all
returns True
if all column values are True
, then using ~
again to reverse this to index rows that are actually all False
:
df3 = df[~(~df[['A', 'B', 'C']]).all(1)]
Upvotes: 2