Created
April 30, 2021 07:10
-
-
Save x/6075ef8f7dbb288e97e79149b7f72b7e to your computer and use it in GitHub Desktop.
pandas range inner join
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In [3]: df1 = pd.DataFrame({"start": [1,2,6], "end": [2,6,9]}) | |
...: df2 = pd.DataFrame({"foo": [1,2,3,4,5,6,7,8,9]}) | |
...: dfm = pd.merge(df1, df2, how="cross") | |
...: dfm.loc[(dfm.foo >= dfm.start) & (dfm.foo < dfm.end)] | |
Out[3]: | |
start end foo | |
0 1 2 1 | |
10 2 6 2 | |
11 2 6 3 | |
12 2 6 4 | |
13 2 6 5 | |
23 6 9 6 | |
24 6 9 7 | |
25 6 9 8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment