Generate dummies if string value matches any row in particular column using pandas.dataframe.str.contains()
<p>If string in "Language_cat" list matches any rows in "Languages" column in df_dat dataframe then generate dummies for that value corresponding to same row:</p>

<pre><code>Language_cat = ['english','french','deutsch','italian','russian','spanish']

for j in Language_cat:
df_dat[j+'lang_cat'] = df_dat['Languages'].apply(lambda x: 1 if df_dat.Languages.str.contains(j) else 0)
</code></pre>

<p>However, this is the error </p>

<pre><code>ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
</code></pre>

<pre><code>Language_cat = ['english','french','deutsch','italian','russian','spanish']

for j in Language_cat:
    df_dat[j+'lang_cat'] = df_dat['Languages'].str.contains(j).astype(int)
</code></pre>

python string pandas dataframe