How To Reproduce The Same Output Of Foverlaps In R With Merge Of Pandas In Python?
I'm doing a merge in R of my tables using the foverlaps function. But I need to reproduce the same output using python. I did a search and I found the merge function on pandas lib
Solution 1:
I can't easily get your exact desired output, but here's a partial solution using IntervalIndex
.
s1 = pd.IntervalIndex.from_arrays(df1['V1'], df1['V2']) # default: closed='right'
s2 = pd.IntervalIndex.from_arrays(df2['V1'], df2['V2'])
df_of_adjacent.set_index(s2, inplace=True)
df_of_adjacent.loc[s1]
V1 V2 subid
(1, 4] 1 4 A
(4, 5] 4 5 B
(4, 5] 4 5 B
(5, 6] 5 6 C
(6, 9] 6 9 D
(6, 9] 6 9 D
(9, 11] 9 11 E
(11, 12] 11 12 F
(11, 12] 11 12 F
(12, 17] 12 17 G
(18, 20] 18 20 I
Post a Comment for "How To Reproduce The Same Output Of Foverlaps In R With Merge Of Pandas In Python?"