I have got OHLC data with missing time frames. Suppose I have the following pandas dataframe denoted by the variable df:
Open High Low Close
2019-04-19 00:00:00 0.67068 0.67123 0.67064 0.67123
2019-04-19 00:02:00 0.67062 0.67425 0.67060 0.67223
Now, I resample that pandas dataframe to fill the missing gap and I get the following:
df = df.resample('T').ffill()
Open High Low Close
2019-04-19 00:00:00 0.67068 0.67123 0.67064 0.67123
2019-04-19 00:01:00 0.67068 0.67123 0.67064 0.67123
2019-04-19 00:02:00 0.67062 0.67425 0.67060 0.67223
From the above, we can see that the missing gap (00:01:00) is filled with the help of ffill(). However, the data in that row (row starting with 00:01:00) is not displayed properly as the opening price should be the same as the closing price of the previous row (row starting with 00:00:00). Likewise, the closing price of that row (row starting with 00:01:00) should be the same as the opening price of the next row (row starting with 00:02:00). The desired output should look like this:
Open High Low Close
2019-04-19 00:00:00 0.67068 0.67123 0.67064 0.67123
2019-04-19 00:01:00 0.67123 0.67123 0.67064 0.67062
2019-04-19 00:02:00 0.67062 0.67425 0.67060 0.67223
How would I resolve this problem in pandas?