Coefficient for pandas.series.interpolate

30 Views Asked by At

I have a pandas series profile for a year with 1 hour interval. I interpolated and resampled the series for '1min' interval. I used method='spline' with order=2 for interpolation. Suppose, I have X as pandas series and I got Y as following: Y = X.resample('1min').interpolate(method = 'spline', order = 2)

Is it possible to get the coefficients for that are used for spline method to get Y?

I can not find any way from the pandas document. I tried to use scipy by converting X values into an array. But I can not find how to interpolate 60 points between to values to receive y and get the coefficients from y.

1

There are 1 best solutions below

0
Gilles Pilon On

pandas passes your series to scipy.interpolate.UnivariateSpline. You can get the coefficients using the get_coeffs() method.

import pandas as pd
from scipy.interpolate import UnivariateSpline as usp
x = pd.Series([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
y = pd.Series([2, 3, 2, 5, 3, 6, 3, 7, 5, 8])
spl = usp(x = x.values, y = y.values, k=2)
coef = spl.get_coeffs()