title: Merging pandas dataframes on multiple conditions (python/pandas)
body: <p>I have a Python/Pandas dataframe (<strong>df1</strong>) consisting of an ID, Chr and position. and a dataframe consisting of the same kind of data (ID, Chr, Position), <strong>df2</strong>. </p>
  
  <p>I would like to obtain a third dataframe (<strong>df3</strong>) that only keeps the rows of df1  based on the Chr-column between df1 and df2, and a position that is within the pos-start and pos-end of df2; additionally it needs to add an ID or row of df2 of which the match was originating. </p>
  
  <p>I found this to be very difficult, does anyone have an idea? </p>
  
  <p>please see below examples: </p>
  
  <p><strong>df1</strong>: </p>
  
  <pre><code>ID1 Chr pos
  a   12  500
  b   12  250
  c   12  300
  d   16  2000
  e   16  1050
  f   16  1075
  d   16  1150
  g   17  8000
  h   17  550
  i   17  500
  </code></pre>
  
  <p><strong>df2</strong>: </p>
  
  <pre><code>ID2 Chr pos-start   pos-end
  x   12  200      400
  y   16  1000    1100
  z   16  1070    1200
  </code></pre>
  
  <p>resulting <strong>df3</strong>:</p>
  
  <pre><code>ID2 ID1 Chr Pos
  x   b   12  250
  x   c   12  300
  y   e   16  1050
  y   f   16  1000
  z   f   16  1075
  z   d   16  1150
  </code></pre>