python - Yfinance KeyError:'regularMarketOpen'
问题描述
我写了下面的代码,但它给出了一个错误。它给出了 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)
在yfinance/base.py
.
推荐阅读
- user-interface - 在 Flutter 中完全自定义 UI 小部件的推荐方法是什么?
- python - 如何删除所有值为 0 的行,忽略第 n 个单元格?
- r - Rattice 中的轮廓图颜色和标签选项
- .net - 指定 PackageReference 依赖 DLL 的构建输出位置
- c# - 使用 Dapper 从多个表中查询数据
- winforms - 我可以将键事件添加到 VB.NET 中的计时器吗
- android - Android 上的 Firebase 凭据无效
- ios - Sign in with Apple button title always displays "SIGN_IN_WITH_APPLE"
- python - 如何在 Python 中获取坐标?
- c# - 重定向到 Blazor 服务器端应用程序中的特定锚点