def func(x,a,b):
return a*x + b
guess = (0.5,0.5,0.5)
fit_df = df.dropna()
col_params = {}
for col in fit_df.columns:
x = fit_df.index.astype(float).values
y = fit_df[col].values
params = curve_fit(func,x,y,guess)
col_params[col] = params[0]
for col in df.columns:
x = df[pd.isnull(df[col])].index.astype(float).values
df[col][x] = func(x,*col_params[col])
print("Extrapolated data")
print(df)
I'm using the code from another post to extrapolate values. I changed the func() so that it is linear not cubic however I get an error "func() takes 3 positional arguments but 4 were give"
Extrapolate values in Pandas DataFrame is where I got the original code. My question is how would I change it so it works with a linear relationship