尝试从 Pandas DataReader 检索数据时出现此错误
Getting this error trying to retrieve data from Pandas DataReader
这是我的代码
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
我该如何解决这个问题?
您的 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)
这是我的代码
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
我该如何解决这个问题?
您的 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)