![]() |
Cubic interpolation in Pandas raises ValueError: The number of derivatives at boundar - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: Cubic interpolation in Pandas raises ValueError: The number of derivatives at boundar (/thread-38909.html) |
Cubic interpolation in Pandas raises ValueError: The number of derivatives at boundar - JaneTan - Dec-09-2022 Using the below weekly dataset, I want to resample to monthly data with cubic conversion. Period Values 20-Jan-89 3 27-Jan-89 4 3-Feb-89 2 10-Feb-89 5 17-Feb-89 3 24-Feb-89 5 3-Mar-89 5 10-Mar-89 6 17-Mar-89 4 24-Mar-89 5 31-Mar-89 7 7-Apr-89 6 14-Apr-89 6 21-Apr-89 4 28-Apr-89 7 5-May-89 5 12-May-89 6 19-May-89 5 26-May-89 7 2-Jun-89 7 I used the code appended below, q= pd.Series(df[series], index=df.index) m = q.resample('M').interpolate(method='cubic')but I get error
RE: Cubic interpolation in Pandas raises ValueError: The number of derivatives at boundar - deanhystad - Dec-09-2022 Works fine if you set the resample period to day. Using week I get a bunch of NaN's. Using month I get your error. Either you don't have enough data to do cubic spline interpolation when resampling by month, or you cannot do cubic interpolation when the sample period is uneven. RE: Cubic interpolation in Pandas raises ValueError: The number of derivatives at boundar - JaneTan - Dec-10-2022 (Dec-09-2022, 08:17 PM)deanhystad Wrote: Works fine if you set the resample period to day. Using week I get a bunch of NaN's. Using month I get your error. Either you don't have enough data to do cubic spline interpolation when resampling by month, or you cannot do cubic interpolation when the sample period is uneven. First, FAME fits a linear spline to the weekly series to create the continuous time series. The spline value for each Friday of the daily series must equal the corresponding weekly series value. For the monthly value, FAME uses the value of the spline for the last day of the month. We can list the data values that we plotted: * REPORT CONVERT( TEST, M, LINEAR) AS "Linear Conversion" Jan Feb Mar Apr May 1989 1989 1989 1989 1989 ---- ---- ---- ---- ---- Linear Conversion 2.86 5.00 7.00 6.43 7.00 The CUBIC technique is similar to the LINEAR technique. FAME performs the aggregation as with the LINEAR technique, except that FAME uses a cubic spline instead of a linear spline to create the continuous time representation of the data. We can list the data values that we plotted: * REPORT CONVERT( TEST, M, CUBIC) AS "Cubic Conversion" Jan Feb Mar Apr May 1989 1989 1989 1989 1989 ---- ---- ---- ---- ---- Cubic Conversion 2.29 5.08 7.00 6.77 7.72 I am trying to transcribe both the linear & cubic technique from FAME code to Python. But I simply can't get the answer using Python linear or cubic interpolation. Do u know how I can solve? Thank you |