Home > Mobile >  Pandas dp dropping row with mutiple strings
Pandas dp dropping row with mutiple strings

Time:02-04

I am trying to drop a row with mutiple string patterns from a csv file a single pattern works but when adding another pattern it doesn't work and does nothing to the file

ols = df[df["Risk"].str.contains("Not") == False] this works

ols = df[df["Risk"].str.contains("Not | yes") == False] this doesn't work

CodePudding user response:

IIUC remove spaces in "Not|yes", for compare with False invert mask by ~:

df[~df["Risk"].str.contains("Not|yes")] 
  •  Tags:  
  • Related