擅长:python、mysql、java
<p>我们可以使用<a href="https://en.wikipedia.org/wiki/Interval_tree#Overlap_test" rel="nofollow noreferrer">Medial- or length-oriented tree: Overlap test</a>:</p>
<pre><code>In [143]: d1 = d1.assign(s=d1.Start+d1.End, d=d1.End-d1.Start)
In [144]: d2 = d2.assign(s=d2.Start+d2.End, d=d2.End-d2.Start)
In [145]: d1
Out[145]:
Start End Remove d s
0 50 60 1 10 110
1 61 105 0 44 166
2 106 150 1 44 256
3 151 160 0 9 311
4 161 180 1 19 341
5 181 200 0 19 381
6 201 400 1 199 601
In [146]: d2
Out[146]:
Start End d s
0 55 100 45 155
1 105 140 35 245
2 151 154 3 305
3 155 185 30 340
4 220 240 20 460
</code></pre>
<p>现在我们可以检查重叠间隔和过滤:</p>
^{pr2}$