Search code examples
pythonpandaspandas-timeindex

How to get column values from another dataframe with a different datetime index


I have a trading dataframes with different intervals, eg. 1 minute and 5 minute. I wish to copy the calculated value from the slower 5min to the 1min dataframe.

e.g. the 1min is thus: enter image description here

I wish to add a forecast_5m or something to that dataframe which has the previous 5min value of the forecast column from the 5min dataframe. Since it is 5min to 1 the sequence of the 1min should then have 5 duplicate values in the column from the previous 5min value found in the other dataframe.

In the picture it is 14:53:00 so it should get the 14:50:00 value, etc. The same for all the minutes to 14:54. I'm getting confused with how to select the last time available as most solutions are about time ranges etc, and not finding the latest closest available in another dataframe.


Solution

  • Did you try to resample the dataframe to one minute intervals with any aggregate?