How to delete rows in python pandas DataFrame using regular expressions?
<p>I have a pattern:</p>

<pre><code>patternDel = "( \\((MoM|QoQ)\\))";
</code></pre>

<p>And I want to delete all rows in pandas dataframe where column <code>df['Event Name']</code> matches this pattern. Which is the best way to do it?  There are more than 100k rows in dataframe.</p>

<p><a href="http://pandas.pydata.org/pandas-docs/version/0.18.1/generated/pandas.Series.str.contains.html" rel="nofollow">str.contains()</a> returns a Series of booleans that we can use to index our frame</p>

<pre><code>patternDel = "( \\((MoM|QoQ)\\))"
filter = df['Event Name'].str.contains(patternDel)
</code></pre>

<p>I tend to keep the things we want as opposed to delete rows.  Since filter represents things we want to delete we use <code>~</code> to get all the rows that don't match and keep them</p>

<pre><code>df = df[~filter]
</code></pre>

python regex pandas