I am attempting to use cubic spline interpolation for a data set (as shown). CubicSpline function requires all numbers to be finite, how can I use it to fill in each NaN value using interpolation?
df = pd.DataFrame()
df['t'] = np.arange(1,11)
n = np.nan
df['r'] = [0, n, n, 0.5, n, 0.3, n, n, n, 0.4]
cs = CubicSpline(df['t'], df['r'])
This spits out the error “y
must contain only finite values.”
I have tried replacing all NaN with 0s, but this returns a spline that is centered around 0 and jumps up for each known value.
New contributor
StungInDaBut is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.