asd
asd

Reputation: 1309

Drop boolean rows based on condition

I have a df from which I need to delete certain rows.

How could I drop all rows where NIT is true and the rest are all false? And the same for FIB?

Drop all rows like these:

number ISM  AAAL    GSOG    GSI     AN      NIT     FIB
2     FALSE FALSE   FALSE   FALSE   FALSE   TRUE    FALSE
222   FALSE FALSE   FALSE   FALSE   FALSE   FALSE   TRUE    

Upvotes: 1

Views: 86

Answers (1)

Stas Buzuluk
Stas Buzuluk

Reputation: 865

mask_NIT_true = df['NIT']
mask_all_exc_NIT_false = ~df.drop('NIT', axis=1).all(axis=1)
df = df.drop(df[mask_NIT_true & mask_all_exc_NIT_false].index)
mask_FIB_true = df['FIB']
mask_all_exc_FIB_false = ~df.drop('FIB', axis=1).all(axis=1)
df = df.drop(df[mask_FIB_true & mask_all_exc_FIB_false].index)

Upvotes: 1

Related Questions