title: Python Pandas Dataframe check column of lists and return ID from another Dataframe
body: <p>I have a pandas dataframe <code>df1</code> which has an index, and a column of lists and looks like:</p>
  
  <pre><code>index   IDList
  0   [1,3,5,7]
  1   [2,4,5,8]
  2   [6,8,9]
  3   [1,2]
  </code></pre>
  
  <p>I have another pandas dataframe <code>df2</code> which has NewID as the index, and a column of lists which looks like this:</p>
  
  <pre><code>NewID   IDList
  1       [3]
  2       [4,5]
  3       [1,7]
  4       [2]
  5       [9,3]
  6       [8]
  7       [6]
  </code></pre>
  
  <p>What I need to do is if any of the items in <code>df1.IDList</code> exist in <code>df2.IDList</code>, then return a list of the relevant <code>df2.NewID</code>. </p>
  
  <p>So the returned <code>d1</code> dataframe would look like:</p>
  
  <pre><code>index   IDList      NewID
  0       [1,3,5,7]   [3,1,2,3,5]
  1       [2,4,5,8]   [4,2,2,6]
  2       [6,8,9]     [7,6,5]
  3       [1,2]       [3,4]
  </code></pre>
  
  <p><strong>EDIT:</strong> Note that in <code>df2</code> there can be ID in <em>IDList</em> that occurs in multiple rows (see <em>ID</em> 3 from <code>df1.IDList</code> and where <em>ID</em> 3 shows up in <code>df2</code> rows 1 AND 5)</p>
  
  <p>I was thinking some kind of <code>np.where</code> statement which incorporates '<code>any</code>' and a list comprehension?  but uncertain how to apply for each <code>IDList</code> in <code>df1</code> where it looks at the whole of <code>df2.IDList</code>.  Maybe some kind of <code>.stack()</code>?  or <code>.melt()</code>?  This would be easy in a spreadsheet with a vlookup of df2...</p>
  
  <p>Help appreciated...</p>