python pandas.Series.str.contains WHOLE WORD
<p>df (Pandas Dataframe) has three rows.</p>

<pre><code>col_name
"This is Donald."
"His hands are so small"
"Why are his fingers so short?"
</code></pre>

<p>I'd like to extract the row that contains "is" and "small".</p>

<p>If I do</p>

<pre><code>df.col_name.str.contains("is|small", case=False)
</code></pre>

<p>Then it catches "His" as well- which I don't want.</p>

<p>Is below query is the right way to catch the whole word in df.series?</p>

<pre><code>df.col_name.str.contains("\bis\b|\bsmall\b", case=False)
</code></pre>

<p>No, the regex <code>/bis/b|/bsmall/b</code> will fail because you are using <code>/b</code>, not the <code>\b</code> that means "word boundary".</p>

<p>Change that and you get a match. I would recommend using</p>

<pre><code>\b(is|small)\b
</code></pre>

<p>That regex is a little faster and a little more legible, at least to me.</p>

python regex pandas dataframe