我收到错误消息:ValueError: time data '2006–01–01' does not match format '%Y-%m-%d'
。我不清楚'2006-01-01'对我来说似乎是正确的格式。
import numpy as np #python library for scientific computing
import pandas as pd #python library for data manipulation and analysis
import matplotlib.pyplot as plt #python library for charting
import yfinance as yf #python library to scrap data from yahoo finance
from pandas_datareader import data as pdr #extract data from internet sources into pandas data frame
yf.pdr_override()
data = pdr.get_data_yahoo('^DJI', start="2006–01–01")
data2 = pdr.get_data_yahoo("MSFT", start="2006–01–01")
data3 = pdr.get_data_yahoo("AAPL", start="2006–01–01")
data4 = pdr.get_data_yahoo("BB.TO", start="2006–01–01")
ax = (data['Close'] / data['Close'].iloc[0] * 100).plot(figsize=(15, 6))
(data2['Close'] / data2['Close'].iloc[0] * 100).plot(ax=ax, figsize=(15,6))
(data3['Close'] / data3['Close'].iloc[0] * 100).plot(ax=ax, figsize=(15,6))
(data4['Close'] / data5['Close'].iloc[0] * 100).plot(ax=ax, figsize=(15,6))
plt.legend(['Dow Jones', 'Microsoft', 'Apple', 'Blackberry'], loc='upper left')
plt.show()
答案 0 :(得分:1)
您的格式使用连字符(U + 002d)。不过,您的start
参数使用破折号(U + 2013)。