I am trying to combine two Pandas frames in two columns. One column has a unique identifier that can be used for a simple .merge()two data. However, the second column merge actually uses .merge_asof(), because it will need to find the nearest date, not the exact date match.
There is a similar question here: Pandas Combine the name and the nearest date , but it was asked and answered almost three years ago, and merge_asof()a much newer addition.
I asked a similar question here a couple of months ago, but the solution was necessary to use merge_asof()without any exact matches.
In the interest of including some code, it would look something like this:
df = pd.merge_asof(df1, df2, left_on=['ID','date_time'], right_on=['ID','date_time'])
where IDwill match exactly, but date_timewill be "close matches."
Any help is greatly appreciated.
source
share