title: Python Pandas - drop rows based on columns of 2 dataframes
body: <p>I have 2 dataframes with a column called <code>frames</code>. The dataframes are about data extracted from 2 videos recorded at the same time of two participants. The data lacks some frames (different per video) due to failed tracking. I want to take an intersection based on the frame integer value <code>df['frame']</code>.</p>
  
  <p>A similar question is posted here: <a href="https://stackoverflow.com/questions/26921943/pandas-intersection-of-two-data-frames-based-on-column-entries">Pandas - intersection of two data frames based on column entries</a>
  , but the accepted answer is a join, not an intersection.</p>
  
  <h1>Example data</h1>
  
  <pre><code>import pandas as pd
  
  df1 = pd.DataFrame(data={'frame': [1, 2, 3]})
  df2 = pd.DataFrame(data={'frame': [2, 3, 4]})
  </code></pre>
  
  <h1>Desired output</h1>
  
  <p>Removed rows not in union of <code>df1['frame']</code> and <code>df2['frame']</code></p>
  
  <pre><code>&gt;&gt;&gt; print(df1)
     frame
  1      2
  2      3
  
  &gt;&gt;&gt; print(df2)
     frame
  0      2
  1      3
  </code></pre>
  
  <p>(I can reset the index after I'm done processing with <code>df1.reset_index(drop=True)</code>)</p>
  
  <h1>Tried</h1>
  
  <p>I thought of first getting the intersection of the frames column of both dataframes with:</p>
  
  <pre><code>df1_idx = df1['frame']
  df2_idx = df2['frame']
  intersection_idx = df1_idx.intersection(df2_idx)
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>File "/*python_path*/site-packages/pandas/core/generic.py", line 3081, in __getattr__
      return object.__getattribute__(self, name)
  AttributeError: 'Series' object has no attribute 'intersection'
  </code></pre>
  
  <p>After getting the frame indexes that are in both dataframes, I was thinking of doing something like (mentioned in: <a href="https://stackoverflow.com/questions/27965295/dropping-rows-from-dataframe-based-on-a-not-in-condition">dropping rows from dataframe based on a &quot;not in&quot; condition</a>):</p>
  
  <pre><code>df1 = df1.drop(df[~df['frame'].isin(intersection_idx)])
  </code></pre>
  
  <h1>System</h1>
  
  <p>Python 3.6.5 with pandas 0.22.0 installed with Anaconda.</p>