python pandas.Series.str.contains words with space
<p>I'm trying to find strings that contain either " internet ", " program ", " socket programming " in the pandas dataframe. </p>

<pre><code>df.col_name.str.contains(" internet | program | socket programming ", case=False)
</code></pre>

<p>Is this right way to do so? or Do I need to escape space using \ and raw string?</p>

<p>Here is a small demo:</p>

<pre><code>In [250]: df
Out[250]:
                                      txt
0                                Internet
1  There is no Internet in this apartment
2                                Program2
3    I am learning socket programming too

In [251]: df.txt.str.contains(" internet | program | socket programming ", case=False)
Out[251]:
0    False
1     True
2    False
3     True
Name: txt, dtype: bool
</code></pre>

<p>If you want to "match" also the first row: <code>Internet</code>:</p>

<pre><code>In [252]: df.txt.str.contains(r"\b(?:internet|program|socket\s+programming)\b", case=False)
Out[252]:
0     True
1     True
2    False
3     True
Name: txt, dtype: bool
</code></pre>

python regex pandas dataframe