I would like to exclude certain values from a polynomial fit to data in a pandas data frame. At the moment my code is:
d = np.polyfit(df1['S_B'],df1['log_norm'],1)
f = np.poly1d(d)
df1['predicted']=getExp(f(df1['S_B']))*df1['Cl']
Is it possible to exclude the values in column log_norm
at rows 0,1 and 6 in the polynomial fit?
The code to get the getExp function is below
from math import e
def getExp(n):
return e**n
CodePudding user response:
I would just create a new dataframe where you have dropped the rows you don't want:
df2 = df1.drop(index=[0, 1, 6])
An alternative would be to make these rows NaN in the log_norm
column, but np.polyfit
might throw an error, in which case you would need to drop these rows anyway.