I have a dataset containing multiple products and their npi values. I want to create linear regressions for each product and output the slope, intercept, rvalue and pvalue in a data frame with the columns for product name slope value, intercept value, rvalue and pvalue.
I have managed to code my for loop for the linear regressions but the appending of the results keeps throwing errors.
this is my code:
result = pd.DataFrame()
for prod in product_array:
data_aggr_period_prod_loop = data_aggr_period_prod.loc[data_aggr_period_prod['product']==prod].sort_values('period')
if len(data_aggr_period_prod_loop) > 1:
x = np.array([date_map[ix] for ix in data_aggr_period_prod_loop['period']])
y1 = np.array(data_aggr_period_prod_loop['npi'])
slope, intercept, rvalue, pvalue, _ = linregress(x, y1)
result = result.append("product", "slope", "intercept", "rvalue", "pvalue")
this code above gave me this error code 'TypeError: append() takes from 2 to 5 positional arguments but 6 were given'
Please can someone tell me how to get the results appended into a dataframe.