I am trying to merge two pandas dataframes each consisting two string columns and one date column.
df1
a b date
100 200 2022-01-03
100 200 2022-01-04
101 200 2022-01-05
101 200 2022-01-06
101 200 2022-01-07
df2
a b date
100 200 2022-01-04
100 200 2022-01-06
101 200 2022-01-03
101 200 2022-01-06
101 200 2022-01-09
The goal is to merge them on a, b, date and take the closest date (forward direction). Desired output:
df
a b date_x date_y
100 200 2022-01-03 2022-01-04
100 200 2022-01-04 2022-01-04
101 200 2022-01-05 2022-01-06 (not 2022-01-03 because it is behind not forward)
101 200 2022-01-06 2022-01-06
101 200 2022-01-07 2022-01-09