Reputation: 442
I have a dataframe containing an asset price (OHLC asset data) such that its index is a datetime. The data shoud be sample in minutes but my dataset have some missing minutes.
To fill the missing data, I just used the function
df.resample("1Min").asfreq()
It fills correctly the minutes within one day, but since my dataframe contains data for different days, it usually fills the minutes until midnight of each day. I would like that, if one specific day contains data from 13:05pm to 20:50pm, it fills minute only between those times, i.e., do not exceed those bounds.
I looked at the documentation for the resample function and couldn't find how it can be done. I appreciate your help!
Upvotes: 2
Views: 484
Reputation: 862591
I believe you need DataFrame.groupby
by days and chain DataFrameGroupBy.resample
with Resampler.first
:
df = df.groupby(df.index.date).resample("1Min").first()
Upvotes: 2