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