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>option using <code>apply</code><br>
<code>df.col.apply(lambda x: 1 in x)</code></p>

<p><strong><em>demo</em></strong><br>
<code>df[df.col.apply(lambda x: 1 in x)]</code><br>
<a href="http://i.stack.imgur.com/wRvd7.png" rel="nofollow"><img src="http://i.stack.imgur.com/wRvd7.png" alt="enter image description here"></a></p>

python pandas