How to apply a function can test whether an element in a list in data frame with python-pandas?
<p>For a data frame <code>df</code>, it has a column <code>col</code> contains <code>list</code> value:</p>

<pre><code> id    col
 1     [1, 10, 23]
 2     [2, 11, 19, 29]
 ..
</code></pre>

<p>I tried:</p>

<pre><code>df[1 in df.col]
</code></pre>

<p>But got an error:</p>

<pre><code>KeyError: True
</code></pre>

<p>Do you know how can I implement it appropriately? Thanks in advance!</p>

<p>try read the "apply" function in pandas <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.apply.html" rel="nofollow">document</a>.</p>

<pre><code>df['has_element'] = df['col'].apply(lambda x: element in x)
</code></pre>

python pandas