user308827
user308827

Reputation: 21961

Interpolating NaNs in pandas dataframe not working

I have the foll. dataframe:

                vals 
2017-07-08  0.169524 
2017-07-09  0.167619 
2017-07-10  0.165714 
2017-07-11  0.163810 
2017-07-12  0.161905 

Based on Extend pandas datetime index to present date, I extend the index to present day and then I want to fill in values by interpolation. I do this:

df.interpolate(how='bicubic', inplace=True)

and get this:

               vals
2017-07-11  0.163810
2017-07-12  0.161905
2017-07-13  0.161905
2017-07-14  0.161905
2017-07-15  0.161905

However, I want the last 3 values from 2017-07-13 to 2017-07-15 not to be the same as the value for 2017-07-12 but be based on whatever trend was happening over the last few values. How can I fix this?

Upvotes: 0

Views: 683

Answers (1)

peterfields
peterfields

Reputation: 316

What you are trying to do is actually extrapolation, not interpolation, and unfortunately pnd.DataFrame does not have a method for it.

You will need to define an extrapolation model, for example by fitting a polynomial curve from your known data and extrapolating it to the remaining index. There is nice explanation on how to do this with time-series indexes over here.

Upvotes: 1

Related Questions