0

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,460
  • 3
  • 31
  • 55

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
  • 296,997
  • 19
  • 147
  • 204