Search code examples
pythonpandasdataframeinterpolation

How to interpolate based on previous behaviour python?


I have a DataFrame tracking Temperatures based on time. it looks like this : 1

For a few days there was a problem and it shows 0 so the plot looks like this: 2

I have replaced the 0 with nans and then used interpolate method but the result is not what I need even I used method = time I get this: 3

So how can I use a customised interpolation or something to correct this based on previous behaviour? Thank you


Solution

  • I would not interpolate. I would just take N elements before the gap and after, compute the average temperature and fill the gap with random values using a normal distribution around the average value (and you can use the std too)