简体   繁体   中英

how to recognise nearest date from another dataframe?

So I have two dataframes, "df_date" containing relatively regular dates concerning the days where the stock market is open, and a "df_exp" containing a list of dates when Futures expire.

I am making "df_frontmth" which will have dates from "df_date" as col1 and col2 will have an expiry date which would be considered "front month" for that col1 date. I don't know how to code the same. Could you help me please ? The front month can be interpreted as the nearest expiry for any non finance readers.

I've tried some for loop functions, but it didn't work well.

Just use concat function from pandas.

df_frontmth = pd.concat([df_date, df_exp], axis=1, sort=False)

If you want to learn more about merge and con canting data frames you can check out this link

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM