title: How to perform a conditional on a column of lists (considering each item in the list) in Pandas
body: <p>Say that I have a column of lists. If the list has at least one item in a set, I want to keep the row, otherwise I want to drop the row. </p>
  
  <p>Here is a minimal example</p>
  
  <pre><code>#create the df 
  d={'range':list(range(0,3))}
  df=pd.DataFrame(d)
  l=[1, 2, 3]
  m =[4, 5, 6]
  n =[1, 7, 8]
  df['var_list']=''
  df['var_list'][0]=l
  df['var_list'][1]=m
  df['var_list'][2]=n
  df.head(3)
  </code></pre>
  
  <p>result</p>
  
  <pre><code>range   var_list
  0   0   [1, 2, 3]
  1   1   [4, 5, 6]
  2   2   [1, 7, 8]
  </code></pre>
  
  <p>And this is the set I want to use</p>
  
  <pre><code>setS = {1, 2}
  </code></pre>
  
  <p>What I'm trying to do is, if any row's list has an item that's in the set, keep that row, otherwise drop that row. </p>
  
  <p>So this is the desired result:</p>
  
  <pre><code>range   var_list
  0   0   [1, 2, 3]
  2   2   [1, 7, 8]
  </code></pre>
  
  <p>What I tried</p>
  
  <pre><code>df2 = df[df['var_list'].isin(setS)]
  </code></pre>
  
  <p>This is the error I got </p>
  
  <pre><code>---------------------------------------------------------------------------
  TypeError                                 Traceback (most recent call last)
  TypeError: unhashable type: 'list'
  
  The above exception was the direct cause of the following exception:
  
  SystemError                               Traceback (most recent call last)
  &lt;ipython-input-56-90ea3b42ebf3&gt; in &lt;module&gt;()
  ----&gt; 1 df2 = df[df['var_list'].isin(setS)]
  
  2 frames
  /usr/local/lib/python3.6/dist-packages/pandas/core/series.py in isin(self, values)
     4512         Name: animal, dtype: bool
     4513         """
  -&gt; 4514         result = algorithms.isin(self, values)
     4515         return self._constructor(result, index=self.index).__finalize__(self)
     4516 
  
  /usr/local/lib/python3.6/dist-packages/pandas/core/algorithms.py in isin(comps, values)
      478             comps = comps.astype(object)
      479 
  --&gt; 480     return f(comps, values)
      481 
      482 
  
  /usr/local/lib/python3.6/dist-packages/pandas/core/algorithms.py in &lt;lambda&gt;(x, y)
      454 
      455     # faster for larger cases to use np.in1d
  --&gt; 456     f = lambda x, y: htable.ismember_object(x, values)
      457 
      458     # GH16012
  
  pandas/_libs/hashtable_func_helper.pxi in pandas._libs.hashtable.ismember_object()
  
  SystemError: &lt;built-in method view of numpy.ndarray object at 0x7fcc893844e0&gt; returned a result with an error set
  </code></pre>