I have 2 dataframes, and would like to insert a row into df1 with a value from df2, based on the nearest datetime and matching ID. Example df's below:
df1
storeID datetime
0 111 2020-01-01 00:50:00
1 222 2020-01-05 05:00:00
2 333 2020-01-10 10:00:00
df2
storeID datetime Value
0 111 2020-01-01 00:55:00 1
1 111 2020-01-05 01:00:00 2
2 222 2020-01-10 05:50:00 3
3 222 2020-01-15 04:55:00 4
4 333 2020-01-20 10:10:00 5
5 333 2020-01-20 11:00:00 6
The output should be something like this:
df1
storeID datetime Value
0 111 2020-01-01 00:50:00 1
1 222 2020-01-05 05:00:00 4
2 333 2020-01-10 10:00:00 5
I came across this question, which is quite similar, however, it is not considering that ID's should match. In the real example do df1 have 50.000+ rows and df2 has 200.000+ rows.