我写了下面的代码,但它给出了一个错误。它给出KeyError:"regularMarketOpen"。
因此,我试图从这里找到解决方案,并更新了base.py,但问题仍然存在。如何修复?
stk_list = ['A', 'AAL', 'AAP', 'AAPL', 'ABBV', 'ABC']
rows = []
for ticker in stk_list:
stk_container = yf.Ticker(ticker)
try:
stk_info = stk_container.info
rows.append(stk_info)
except IndexError as e:
print(f'{ticker}: {e}') #print the ticker and the error
df = pd.DataFrame(rows)
subset_df = df[['symbol', 'longName', 'sector', 'industry', 'trailingPE', 'priceToBook', 'trailingEps', 'dividendYield']]
subset_df.head(10)
KeyError Traceback (most recent call last)
<ipython-input-8-15d77c81339f> in <module>
6 stk_container = yf.Ticker(ticker)
7 try:
----> 8 stk_info = stk_container.info
9 rows.append(stk_info)
10 except IndexError as e:
/opt/anaconda3/lib/python3.7/site-packages/yfinance/ticker.py in info(self)
136 @property
137 def info(self):
--> 138 return self.get_info()
139
140 @property
/opt/anaconda3/lib/python3.7/site-packages/yfinance/base.py in get_info(self, proxy, as_dict, *args, **kwargs)
414
415 def get_info(self, proxy=None, as_dict=False, *args, **kwargs):
--> 416 self._get_fundamentals(proxy)
417 data = self._info
418 if as_dict:
/opt/anaconda3/lib/python3.7/site-packages/yfinance/base.py in _get_fundamentals(self, kind, proxy)
317 self._info.update(data[item])
318
--> 319 self._info['regularMarketPrice'] = self._info['regularMarketOpen']
320 self._info['logo_url'] = ""
321 try:
KeyError: 'regularMarketOpen'
我通过粘贴解决了这个问题
url = "{}/{}".format(self._scrape_url, self.ticker)
高于
data = utils.get_json(url+'/financials', proxy)
在CCD_ 1中。