Я пытаюсь получить данные 50 компаний в Nifty50.
import bs4 as bs
import datetime as dt
import os
import pandas as pd
import pandas_datareader.data as web
import pickle
import requests
def save_nifty50_tickers():
resp=requests.get('https://en.wikipedia.org/wiki/NIFTY_50')
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("nifty50tickers.pickle", "wb") as f:
pickle.dump(tickers, f)
print(tickers)
return tickers
#save_nifty50_tickers()
def get_data_from_yahoo(reload_nifty50= False):
if reload_nifty50:
tickers = save_nifty50_tickers()
else:
with open("nifty50tickers.pickle", "rb") as f:
tickers = pickle.load(f)
if not os.path.exists('stock_dfs'):
os.makedirs('stock_dfs')
start = dt.datetime(2000,1,1)
end =dt.datetime(2020,2,29)
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()
ошибка, которую я получаю,
Warning (from warnings module):
File "C:\Users\vishal\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas_datareader\compat\__init__.py", line 7
from pandas.util.testing import assert_frame_equal
FutureWarning: pandas.util.testing is deprecated. Use the functions in the public API at pandas.testing instead.
Adani Ports
Traceback (most recent call last):
File "C:\Users\vishal\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas_datareader\yahoo\daily.py", line 157, in _read_one_data
data = j["context"]["dispatcher"]["stores"]["HistoricalPriceStore"]
KeyError: 'HistoricalPriceStore'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/vishal/AppData/Local/Programs/Python/Python37-32/ep5 nifty 50.py", line 43, in <module>
get_data_from_yahoo()
File "C:/Users/vishal/AppData/Local/Programs/Python/Python37-32/ep5 nifty 50.py", line 39, in get_data_from_yahoo
df=web.DataReader(ticker, 'yahoo', start, end)
File "C:\Users\vishal\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\util\_decorators.py", line 214, in wrapper
return func(*args, **kwargs)
File "C:\Users\vishal\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas_datareader\data.py", line 387, in DataReader
session=session,
File "C:\Users\vishal\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas_datareader\base.py", line 251, in read
df = self._read_one_data(self.url, params=self._get_params(self.symbols))
File "C:\Users\vishal\AppData\Local\Programs\Python\Python37-32\lib\site-pack