Python Forum
Cubic interpolation in Pandas raises ValueError: The number of derivatives at boundar
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cubic interpolation in Pandas raises ValueError: The number of derivatives at boundar
#1
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

Error:
ValueError: The number of derivatives at boundaries does not match: expected 3, got 0+0
Reply
#2
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.
Reply
#3
(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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Cubic spline Graph Interpretation how? GREEN369 1 162 Apr-15-2024, 08:24 AM
Last Post: Gribouillis
  which order for bicubic interpolation biba 0 2,337 Jan-25-2018, 01:53 PM
Last Post: biba

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020