intersection 2 pandas dataframe

Viewed 381

in my problem I have 2 dataframes mydataframe1 and mydataframe2 as below.

mydataframe1
Out[13]:
  Start   End       Remove     
  50      60        1  
  61      105       0  
  106     150       1  
  151     160       0  
  161     180       1  
  181     200       0  
  201     400       1  


mydataframe2
Out[14]: 
    Start   End  
    55      100
    105     140
    151     154
    155     185
    220     240    

From mydataframe2 I would like to remove the rows for which the interval Start-End are contained (also partially) in any of the "Remove"=1 intervals in mydataframe1. In other words there should not be any itnersection between the intervals of mydataframe2 and each of the intervals in mydataframe1

in this case mydataframe2 becomes

mydataframe2
Out[15]: 
    Start   End  
    151     154
5 Answers
Related