Delete row if any column contains one of the keywords
You can join all columns together with +
or apply
and then create mask by Series.str.contains
with joined values by |
for regex OR
:
df = df[~(df['Brand']+df['ID']+df['Description']).str.contains('|'.join(keywords))]
Or:
df = df[~df.apply(' '.join, 1).str.contains('|'.join(keywords))]print (df) Brand ID Description1 iPhone DF747 battery2 Acer KH298 exchanged for a nokia
If need case not sensitive add case
paremeter:
df = df[~df.apply(' '.join, 1).str.contains('|'.join(keywords), case=False)]print (df) Brand ID Description1 iPhone DF747 battery
df = df[~(df.stack().str.contains('|'.join(keywords)).any(level=0))]
or
df = df[~(df.astype(str).sum(axis=1).str.contains('|'.join(keywords)))]
Output
Brand ID Description1 iPhone DF747 battery2 Acer KH298 exchanged for a nokia