title: Pandas: Comparing multiple columns to merge dataframes
body: <p>I have two dataframes much larger than this, but they are in the form:</p>
  
  <pre><code>df1 = pd.DataFrame({'col1': ['a', 'b', 'b', 'c'],
                     'start': [1, 5, 10, 15],
                     'end': [4, 9, 14, 19]})
  df2 = pd.DataFrame({'col1': ['a', 'b', 'b', 'c'],
                     'value': [2, 6, 12, 20],
                    'etc': [1, 2, 3, 4]})
  </code></pre>
  
  <p>I want to merge them based on checking two things in this order: 1) that <code>col1</code> matches, 2) that <code>value</code> is between <code>start</code> and <code>end</code>. I was thinking something like (but the first <code>==</code> line doesn't work):</p>
  
  <pre><code>if df1.col1 == df2.col1:
      if df1.start &lt; df2.value &lt; df1.end:
          df1.merge(df2)
  </code></pre>
  
  <p>I don't know if that will check all lines in df1 against all lines in df2 though? The desired output for this example would be:</p>
  
  <pre><code>dfoutput = pd.DataFrame({'col1': ['a', 'b', 'b'],
                          'start': [1, 5, 10],
                          'end': [4, 9, 14],
                          'value': [2, 6, 12],
                          'etc': [1, 2, 3]})
  </code></pre>