I have two dataframes. I would like to merge the second dataframe to the first one on nearest time point.
Example: (df1)
user t
Ajay 2020-05-05 18:00:00
Ajay 2020-05-05 20:00:00
Ajay 2020-05-06 17:15:00
Ajay 2020-05-06 20:30:00
Ajay 2020-05-06 21:15:00
Example: (df2)
user t flag
Ajay 2020-05-05 18:04:00 10
Ajay 2020-05-05 18:12:00 7
Ajay 2020-05-05 20:02:00 9
Ajay 2020-05-06 17:13:00 2
Ajay 2020-05-06 17:45:00 5
Ajay 2020-05-06 20:30:00 8
Ajay 2020-05-06 21:12:00 9
df2 should be merged on df1 on nearest time stamp. Based on my limited understanding, pandas merge only on exact value. is it possible?
expected output:
user t flag
Ajay 2020-05-05 18:00:00 10
Ajay 2020-05-05 20:00:00 9
Ajay 2020-05-06 17:15:00 2
Ajay 2020-05-06 20:30:00 8
Ajay 2020-05-06 21:15:00 9