title: Improve efficiency of looping through pandas dataframe
body: <p>I'm guessing there is a more efficient way to make the comparisons that I am making.</p>
  
  <p>Currently, I have two pandas DataFrames.  </p>
  
  <p>DataFrame <code>A</code> looks like this:</p>
  
  <pre><code>    Location    Tier    Other
  0   100         1       'Blah'
  1   200         1       'Blah'
  2   10          1       'Blah'
  3   30          1       'Blah'
  4   500         1       'Blah'
  </code></pre>
  
  <p>DataFrame <code>B</code> looks like this:</p>
  
  <pre><code>    Start   Stop    Tier    Other
  0   400     600     1       'Blah'
  1   5       20      2       'Blah'
  </code></pre>
  
  <p>I would like to find all rows whose <code>Location &gt; Start</code> and <code>Location &lt; End</code> and <code>Tier</code> matches. So, in the above example, row 4 from DataFrame <code>A</code> has a <code>Location</code> that is greater than <code>400</code> but less than <code>600</code> and the <code>Tier</code> is ` in both DataFrames, so it should get returned somehow, like appending to a final DataFrame.</p>
  
  <p>This is how I am making the comparisons now:</p>
  
  <pre><code>for i in A():
      matching = matching.append(B[(B.Tier == i.Tier) &amp; (B.Start &lt; i.Location) &amp; (B.Stop &gt; i.Location)], ignore_index=True)
  return matching
  </code></pre>
  
  <p>Is there a faster way of accomplishing this, as my code runs quite slowly?</p>