我正在尝试使用熊猫获得两列的相关方程。
我尝试使用.corr,但是它只给出相关性而没有等式。有帮助吗?
import pandas as pd
excel_file='choclates.xlsm'
data= pd.read_excel(excel_file)
data2 = pd.read_excel(excel_file, sheetname=1)
data9=data2['rating'].corr(data2['cocoa'])
answer = -0.1643880204966386
答案 0 :(得分:1)
found an answer, this is my code:
'x=data2.cocoa
y=data2.rating
x2 = np.array(x)
y2 = np.array(y)
slope, intercept ,r_value,pvalue,std_err = stats.linregress(x2,y2)
line= slope*x2+intercept
plt.plot(x2, line, 'b', label='y={:.2f}x+{:.2f}'.format(slope,intercept))
plt.ylabel('rating')
plt.xlabel('cocoa')
plt.legend(fontsize=14)
plt.show()`
thank you for the help