Conditional data selection with text string data in pandas dataframe
<p>I've looked but seem to be coming up dry for an answer to the following question. </p>

<p>I have a pandas dataframe analogous to this (call it 'df'):</p>

<pre><code>        Type              Set
    1   theGreen          Z
    2   andGreen          Z           
    3   yellowRed         X
    4   roadRed           Y
</code></pre>

<p>I want to add another column to the dataframe (or generate a series) of the same length as the dataframe (= equal number of records/rows) which assigns a numerical coding variable (1) if the Type contains the string "Green", (0) otherwise. </p>

<p>Essentially, I'm trying to find a way of doing this:</p>

<pre><code>   df['color'] = np.where(df['Type'] == 'Green', 1, 0)
</code></pre>

<p>Except instead of the usual numpy operators (&lt;,>,==,!=, etc.) I need a way of saying "in" or "contains". Is this possible? Any and all help appreciated! </p>