I have a set of data from a pd.DataFrame
which looks like this, with a 3rd-order polynomial fitted to it:
# Find the 3rd-order polynomial which fits the SED
coefs = poly.polyfit(x, y, 3) # find the coeffs
x_new = np.linspace(lower, upper, num=len(x)*10) # space to plot the fit
ffit = poly.Polynomial(coefs) # find the polynomial
How could I find the straight line that fits only part of the data, for example, just the downward slope within 9.5 < x < 15 ?
I could slice the dataframe into pieces with
left = pks[pks[xvar] < nu_to]
right = pks[pks[xvar] > nu_to]
but I'd like to avoid that, since I'll have to do the same thing with many datasets.
This question is about MatLab This current question is a distillation of my previous one.