pd merge asof

Solutions on MaxInterview for pd merge asof by the best coders in the world

showing results for - "pd merge asof"
Catalina
17 Jan 2018
1>>> left = pd.DataFrame({"a": [1, 5, 10], "left_val": ["a", "b", "c"]})
2>>> left
3    a left_val
40   1        a
51   5        b
62  10        c
7
8>>> right = pd.DataFrame({"a": [1, 2, 3, 6, 7], "right_val": [1, 2, 3, 6, 7]})
9>>> right
10   a  right_val
110  1          1
121  2          2
132  3          3
143  6          6
154  7          7
16
17>>> pd.merge_asof(left, right, on="a")
18    a left_val  right_val
190   1        a          1
201   5        b          3
212  10        c          7
Sara
19 Mar 2020
1pd.merge_asof(df1, df2, on='col', direction='nearest')