我试图为标准普尔500指数的历史价值添加一条趋势线;P500,但当我试图添加趋势线时,它没有出现,只有标准普尔500指数;P500值出现在图表中。(““拿督”在挪威语中的意思是“日期”。)
这是我的密码:
##################### Load the data
df = pd.read_csv("SP500.csv", delimiter=r",", names = ["Date","Open", "High",
"Low", "Close", "S&P500",
"Volume"])
df = df.drop(columns=['Open', 'High', 'Low', 'Close', 'Volume'])
df["Dato"] = df["Date"]
df2 = pd.read_excel("OSEBX.xlsx", names = ["Date", "OSEBX"])
df.set_index('Date', inplace=True)
df2.set_index('Date', inplace=True)
df3 = df.join(df2)
df["Dato"] = pd.to_datetime(df3["Dato"])
################################ Graph
t = np.array(range(0, len(df["Dato"])))
x = np.array(df3["OSEBX"])
y = np.array(df3["S&P500"])
plt.scatter(t,x, s=1)
z = np.polyfit(x, t, 1)
p = np.poly1d(z)
plt.plot(x,p(x),"bs", linewidth=20)
plt.show()
相关问题 更多 >
编程相关推荐