这是我的代码
def competitor_stock_data_report():
import datetime
import pandas_datareader.data as web
date_time = datetime.datetime.now()
date = date_time.date()
stocklist = ['LAZ','AMG','BEN','LM','EVR','GHL','HLI','MC','PJT','MS','GS','JPM','AB']
start = datetime.datetime(date.year, date.month, date.day)
end = datetime.datetime(date.year-1, date.month, date.day)
for x in stocklist:
df = web.DataReader(x, 'google', start, end)
print(df['Close'].tail(n=1))
print(df['Close'].head(n=1))
当我静态导入日期时,这应该有效。
这是我得到的错误:
File "pandas\_libs\parsers.pyx", line 565, in pandas._libs.parsers.TextReader.__cinit__ (pandas\_libs\parsers.c:6260)
pandas.errors.EmptyDataError: No columns to parse from file
我该如何解决这个问题?
答案 0 :(得分:1)
您的end
日期早于start
日期:
start = datetime.datetime(date.year, date.month, date.day)
end = datetime.datetime(date.year-1, date.month, date.day)
它应该是:
start = datetime.datetime(date.year-1, date.month, date.day)
end = datetime.datetime(date.year, date.month, date.day)