0

I'm a bit new to pandas.interpolate.

I have a pandas dataframe indexed by years from 2011 from 2017. I sometimes have missing values so I used interpolate with method='linear' and limit_direction='both' to fill the gaps.

The screenshot below features the original dataframe (top) and the interpolation result (bottom).

When a missing value is located between non-missing values, everything works fine: on the example below, a brand new value is generated in 2016.

But when the NAs are at the beginning or at the end of the series, I am not satisfied by the result because it turns out that it is just a mere copy of the next non-missing values: on the example below, you can see that 2011 and 2012 were given the same value as 2013.

enter image description here

Then, I tried to use method='polynomial' with order=2 to get a "smoother" interpolation, but I got the following error:

ValueError: number of derivatives at boundaries.

Can someone explain to me why I'm doing it wrong and which method I could use to get a nice interpolation, including for the first and the last value?

R. Bourgeon
  • 923
  • 1
  • 9
  • 25

0 Answers0