[英]module 'pandas_datareader.data' has no attribute 'Datareader'
I am trying to run the code below, I am using Spyder.我正在尝试运行下面的代码,我正在使用 Spyder。 I have another file that also uses pandas_datareader, and I never get an error message on that file, which is also run on Spyder.
我有另一个文件也使用了 pandas_datareader,但我从未在该文件上收到错误消息,该文件也在 Spyder 上运行。 In addition the other file also uses yahoo, so I don't think that is the issue either.
此外另一个文件也使用雅虎,所以我认为这也不是问题。 My questions is:is there something particular in my code that is causing this file to not have a data reader module?
我的问题是:我的代码中是否有什么特别的东西导致这个文件没有数据读取器模块?
import bs4 as bs
import datetime as dt
import os
import pandas_datareader.data as web
import pickle
import requests
def save_sp500_tickers():
resp=requests.get('https://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
tickers.append(ticker)
with open('sp500tickers.pickle','wb') as f:
pickle.dump(tickers, f)
print(tickers)
return tickers
#save_sp500_tickers()
def get_data_from_yahoo(reload_sp500=False):
if reload_sp500:
tickers=save_sp500_tickers()
else:
with open('sp500tickers.pickle','rb') as f:
tickers=pickle.load(f)
if not os.path.exists('stock_dfs'):
os.makedirs('stock_dfs')
start=dt.datetime(2016,1,1)
end=dt.datetime(2019,5,27)
for ticker in tickers:
print(ticker)
if not os.path.exists('stock_dfs/{}.csv'.format(ticker)):
df=web.Datareader(ticker, 'yahoo', start, end)
df.to_csv('stock_dfs/{}.csv'.format(ticker))
else:
print('Already have {}' .format(ticker))
get_data_from_yahoo()
Try this:尝试这个:
from pandas_datareader import data, wb
then use:然后使用:
data.DataReader('path')
to read the file读取文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.