Pandas slicing by element in cell
<p>What is the best way to slice by looking for a single element within a cell? I know how to do it with the .isin() function where the cell element is in a list. But I am actually looking for the reverse:</p>

<pre><code>id       vals
1        ['wow', 'very', 'such']
2        ['wow', 'such']
3        ['very', 'such']
</code></pre>

<p>I wanted something like this (but this doesn't work): </p>

<pre><code>df['very' in df['vals']]

id       vals
1        ['wow', 'very', 'such']
3        ['very', 'such']
</code></pre>

<p>I think an alternative is to use apply(), matching on the value, but it seems a little inelegant.</p>

<pre><code>df[df.vals.apply(lambda x: 'very' in x)]
Out[9]: 
                vals
0  [wow, very, such]
2       [very, such]
</code></pre>

python pandas slice