我运行以下代码:
import pandas_datareader.data as web
from datetime import date, datetime, timedelta
#
datetime_now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
todays_date = date.today() # retreived in YYYY-MM-DD format
n = 7
date_n_days_ago = date.today() - timedelta(days=n)
#
mylist = ['AAPL', 'BEML.NS', 'BAJAJ-AUTO.NS', 'M&M.NS', 'JINDALSTEL.NS', 'L&TFH.NS']
#
for yahoo_symbol in mylist:
try:
stock_data = web.DataReader(yahoo_symbol, 'yahoo', date_n_days_ago, todays_date)
print "success in retreiving data for: ",yahoo_symbol
except:
print "failed in retreiving data for: ",yahoo_symbol
这是我收到的输出:
success in retreiving data for: AAPL
success in retreiving data for: BEML.NS
failed in retreiving data for: BAJAJ-AUTO.NS
failed in retreiving data for: M&M.NS
success in retreiving data for: JINDALSTEL.NS
failed in retreiving data for: L&TFH.NS
我的疑问:当符号为“BAJAJ-AUTO.NS”或“M&M.NS”时,为什么我无法使用 pandas_datareader 检索雅虎股票数据,但当符号为“AAPL”或“BEML.NS”时可以这样做. 是否有任何解决方法来检索这些数据?
PS:我注意到,只要股票代码包含“&”或“-”,我就无法使用 pandas_datareader 从 Yahoo Finance 检索该数据
谢谢你。