1

I have a pandas dataframe that looks like this:

    Beer            Rating
0   Heineken        Good
1   Budweiser       Bad
2   Coors Light     Bad

and a list that looks like this:

bad_beers = ["Light", "0.0%"]

How to delete every row in a pandas dataframe that contains a given string from a list?

The desired output should look like this:

    Beer       Rating
0   Heineken   Good
1   Budweiser  Bad
sudonym
  • 3,788
  • 4
  • 36
  • 61

1 Answers1

2

We can use str.contains

df[~df.Beer.str.contains('Light')]
Out[364]: 
        Beer Rating
0   Heineken   Good
1  Budweiser    Bad

If list contain more items using | .

df[~df.Beer.str.contains('Light|Heineken')]
Out[365]: 
        Beer Rating
1  Budweiser    Bad
BENY
  • 317,841
  • 20
  • 164
  • 234