title: Python Pandas: Merge or Filter DataFrame by Another. Is there a Better Way?
body: <p>One situation I sometimes encounter is, I have two dataframes (<code>df1</code>, <code>df2</code>) and I want to create a new dataframe (<code>df3</code>) based on the intersection of multiple columns between <code>df1</code> and <code>df2</code>.</p>
  
  <p>For example, I want to create <code>df3</code> by filtering <code>df1</code> by columns <code>Campaign</code> and <code>Group</code>.</p>
  
  <pre><code>import pandas as pd
  df1 = pd.DataFrame({'Campaign':['Campaign 1', 'Campaign 2', 'Campaign 3', 'Campaign 3', 'Campaign 4'], 'Group':['Some group', 'Arbitrary Group', 'Group 1', 'Group 2', 'Done Group'], 'Metric':[245,91,292,373,32]}, columns=['Campaign', 'Group', 'Metric'])
  df2 = pd.DataFrame({'Campaign':['Campaign 3', 'Campaign 3'], 'Group':['Group 1', 'Group 2'], 'Metric':[23, 456]}, columns=['Campaign', 'Group', 'Metric'])
  </code></pre>
  
  <p><code>df1</code></p>
  
  <pre><code>     Campaign            Group  Metric
  0  Campaign 1       Some group     245
  1  Campaign 2  Arbitrary Group      91
  2  Campaign 3          Group 1     292
  3  Campaign 3          Group 2     373
  4  Campaign 4       Done Group      32
  </code></pre>
  
  <p><code>df2</code></p>
  
  <pre><code>     Campaign    Group  Metric
  0  Campaign 3  Group 1      23
  1  Campaign 3  Group 2     456
  </code></pre>
  
  <p><strong>I know I can do this with merge</strong>...</p>
  
  <pre><code>df3 = df1.merge(df2, how='inner', on=['Campaign', 'Group'], suffixes=('','_del'))
  #df3
       Campaign    Group  Metric  Metric_del
  0  Campaign 3  Group 1     292          23
  1  Campaign 3  Group 2     373         456
  </code></pre>
  
  <p>but then I have to figure out how to <code>drop</code> columns that end with <code>_del</code>.  I guess this:</p>
  
  <pre><code>df3.select(lambda x: not re.search('_del', x), axis=1)
  ##The result I'm going for but required merge, then select (2-steps)
       Campaign    Group  Metric
  0  Campaign 3  Group 1     292
  1  Campaign 3  Group 2     373
  </code></pre>
  
  <p><strong>Questions</strong></p>
  
  <p>What I'm mainly interested in is returning <code>df1</code> that's simply filtered on <code>df2</code>'s <code>Campaign|Group</code> values.</p>
  
  <ol>
  <li><p>Is there a <strong>better</strong> way to return <code>df1</code> without resorting to <code>merge</code>? </p></li>
  <li><p>Is there a way to <code>merge</code> but NOT return <code>df2</code>'s columns to the <code>merge</code> and returning only <code>df1</code>'s columns?</p></li>
  </ol>