Count how many attributes have a word as a substring of longer text value
<p>For example, if I have a data frame that looks like this:</p>

<pre><code>id    title    
1     assistant
2     chief executive officer
3     director
4     chief operations officer
5     assistant manager
6     producer
</code></pre>

<p>If I wanted to find how many <code>title</code> have the word <strong>assistant</strong> in them, the result should be <code>2</code>. If I wanted to find how many <code>title</code> have <strong>chief</strong> in them, the result should be <code>2</code> as well.</p>

<p>Is there a fast way to do this using pandas?</p>

<p>Use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.count.html" rel="nofollow"><code>str.count</code></a> with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.sum.html" rel="nofollow"><code>sum</code></a>:</p>

<pre><code>print (df.title.str.count('chief'))
0    0
1    1
2    0
3    1
4    0
5    0
Name: title, dtype: int64

print (df.title.str.count('chief').sum())
2

print (df.title.str.count('assistant').sum())
2
</code></pre>

python string pandas dataframe count