col = ['rss','intercept'] + ['coef_x_%d'%i for i in range(1,16)]
ind = ['model_pow_%d'%i for i in range(1,16)]
coef_matrix_simple = pd.DataFrame(index=ind, columns=col)
for i in range(1,16):
coef_matrix_simple.iloc[i-1,0:i+2] = linear_regression(df, power=i, models_to_plot=models_to_plot)
pd.options.display.float_format = '{:,.2g}'.format
coef_matrix_simple
np.savetxt('output.csv', coef_matrix_simple, delimiter =" ")
I want to save the coef_matrix_simple along with col values as column name and ind values in the csv file. saving the coef_matrix_simple gives only numbers without any column name.
You could try with pandas' DataFrame.to_csv()
method. The usage in your case would be
coef_matrix_simple.to_csv("output.csv", sep=" ")
More information here: https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_csv.html
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments