【发布时间】:2020-03-14 03:41:45
【问题描述】:
我有这段代码,它从维基百科获取符号列表,然后从 yahoofinance 获取股票数据。这是一个简单的代码,直到几天前都可以正常工作,但由于某种原因,我在许多股票上都收到了 unable to read symbol 错误。雅虎是这样做的吗?我能做些什么来解决这个错误。我不能忽略这一点,因为超过 50 个符号是 NaN,当我重新运行代码时,错误中会出现不同的符号
pandas_datareader 版本:0.8.1 代码:
import datetime
import pandas as pd
import numpy as np
import csv
from pandas_datareader import data as web
import matplotlib
import matplotlib.pyplot as plt
import requests
import bs4 as bs
from urllib.request import urlopen
from bs4 import BeautifulSoup
import tqdm
from pandas import DataFrame
import seaborn as sns
resp = requests.get('http://en.wikipedia.org/wiki/List_of_S%26P_500_companies')
soup = bs.BeautifulSoup(resp.text, 'lxml')
table = soup.find('table', {'class': 'wikitable sortable'})
tickers = []
for row in table.findAll('tr')[1:]:
ticker = row.findAll('td')[0].text.strip()
tickers.append(ticker)
start = datetime.date(2008,11,1)
end = datetime.date.today()
# df = web.get_data_yahoo(tickers, start, end)
df = web.DataReader(tickers, 'yahoo', start, end)
错误:
C:\ProgramData\Anaconda3\lib\site-packages\pandas_datareader\base.py:270: SymbolWarning: Failed to read symbol: 'T', replacing with NaN.
warnings.warn(msg.format(sym), SymbolWarning)
C:\ProgramData\Anaconda3\lib\site-packages\pandas_datareader\base.py:270: SymbolWarning: Failed to read symbol: 'BKR', replacing with NaN.
warnings.warn(msg.format(sym), SymbolWarning)
C:\ProgramData\Anaconda3\lib\site-packages\pandas_datareader\base.py:270: SymbolWarning: Failed to read symbol: 'BRK.B', replacing with NaN.
warnings.warn(msg.format(sym), SymbolWarning)
【问题讨论】:
-
在这个旧的github问题中,作者建议使用
datetime.datetime(Y,m,d)作为开始和结束,而不是datetime.date或者尝试更改为datetime? -
@mgrollins 您能否分享讨论此问题或可能修复的链接?
-
我能够得到所有的符号,最近我收到了这个警告!
-
哦,对不起,我以为我把它丢了:github.com/pydata/pandas-datareader/issues/285
-
我没有收到任何警告
标签: python-3.x pandas pandas-datareader