Q: Rolling over dataframe pandas and update values if NaN I want to use rolling function on my dataframe.
Here my series :




index
date
id
value_dex




90256
2021-05-10 01:45:20
101904285
7.6


90257
2021-05-10 01:45:20
101904285
7.6


90258
2021-05-10 02:00:00
101904285
NaN


90260
2021-05-10 02:00:44
101904285
6.9


90261
2021-05-10 02:00:44
101904285
NaN




What I want :




index
date
id
value_dex




90256
2021-05-10 01:45:20
101904285
7.6


90257
2021-05-10 01:45:20
101904285
7.6


90258
2021-05-10 02:00:00
101904285
7.6


90260
2021-05-10 02:00:44
101904285
6.9


90261
2021-05-10 02:00:44
101904285
6.9




I would like to drag the values in the column over 30 minutes if NaN. However, I also want the dragging to stop when a new value is encountered on the 30 minute range (in this case, we drag the new value over 30 minutes).
I tried that :

ffill = lambda x: pd.DataFrame(x.rolling('30T', on='Date')[y].max(),
                                       index=x.index)
        
        data[y] = data.groupby('ID', as_index=False).apply(ffill)

But it doesn't work when there is a new value during the rolling. Do you have any solutions in order to resolve my problem ? Maybe an existing function ? Thanks a lot !

A: I believe you can try to use this as a filler for you NaN values:
data.fillna(method='ffill')

