Jul-19-2019, 01:59 PM
I have a data frame df as follows:
I'm totally used to R, there I know how to proceed but I don't know how to do the same in python. However, I need to fit each group in regards to H2 and CO and extract the corresponding regression coefficients.
Can somebody please help me?
Board Time CO H2 0 B000653BE 05.11.2018 13:28 89720 20320 1 B000653BE 05.11.2018 13:32 112760 35070 2 B000653BE 05.11.2018 13:36 130783 47063 (...) Board Time CO H2 B000653BF 08.11.2018 14:04 261254 217003 B000653BF 08.11.2018 14:08 261395 216402 B000653C2 05.11.2018 13:28 95564 49094 B000653C2 05.11.2018 13:32 90978 73274 B000653C2 05.11.2018 13:36 87743 93204 (...)And I want to fit each group of Board via
def func_exp(x, a, b, c): #c = 0 return a * np.exp(b * x) + c def exponential_regression (x_data, y_data): popt, pcov = curve_fit(func_exp, x_data, y_data, p0 = (1000.1, 0.01, 1000000), maxfev=5000 ) print(popt) return func_exp(x_data, *popt)but I can't figure out how to proceed. I thought about
df.groupby('Board').apply(exponential_regression(df.index, df["H2"]))but I only get different errors (when I try to adjust the syntax somehow..)
I'm totally used to R, there I know how to proceed but I don't know how to do the same in python. However, I need to fit each group in regards to H2 and CO and extract the corresponding regression coefficients.
Can somebody please help me?