Consider the following dataframe:
df = pd.DataFrame([np.nan, np.nan,1, 5,np.nan, 6, 6.1 , np.nan,np.nan])
I would like to use the pandas.DataFrame.interpolate
method to linearly extrapolate the dataframe entries at the starting and ending rows, similar to what I get if I do the following:
from scipy import interpolate
df_num = df.dropna()
xi = df_num.index.values
yi = df_num.values[:,0]
f = interpolate.interp1d(xi, yi, kind='linear', fill_value='extrapolate')
x = [0, 1 , 7, 8]
print(f(x))
[-7. -3. 6.2 6.3]
It seems that the 'linear' option in pandas interpolate
calls numpy's interpolate method which doesn't do linear extrapolation. Is there a way to call the built-in interpolate method to achieve this?