How to delete rows in python pandas DataFrame using regular expressions?

str.contains() returns a Series of booleans that we can use to index our frame

patternDel = "( \\((MoM|QoQ)\\))"
filter = df['Event Name'].str.contains(patternDel)

I tend to keep the things we want as opposed to delete rows. Since filter represents things we want to delete we use ~ to get all the rows that don’t match and keep them

df = df[~filter]

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)