I have a df like,
ds value
====================================
1 2023-07-01 17:00:00 100
2 2023-07-01 18:00:00 0
3 2023-07-01 19:00:00 300
I want to set the mean of 1st and 3rd rows value into the 2nd row like this
ds value
====================================
1 2023-07-01 17:00:00 100
2 2023-07-01 18:00:00 150
3 2023-07-01 19:00:00 200
And some times it may be more that one rows which will be having 0, is there a way to handle that dynamically.
Any help is much appreciated
Thanks,
>Solution :
IIUC use Series.replace with Series.interpolate:
df['value'] = df['value'].replace(0, np.nan).interpolate()