0

当我尝试在 yahoo_fin(见下文)的帮助下从苹果下载当前价格时,我收到错误消息 KeyError:'adjclose'。任何人都知道为什么以及如何解决它?

谢谢

from yahoo_fin import stock_info as si
ab=si.get_live_price('APPL')
print(ab)  ´´´

Complete Erro massage:

---------------------------------------------------------------------------

KeyError                                  Traceback (most recent call last)

<ipython-input-71-71025ce2a3a4> in <module>
      1 #self._history["Current Price"]=self._history["Ticker"].apply(lambda x: si.get_live_price(x))
----> 2 ab=si.get_live_price('APPL')
      3 ab

~/opt/anaconda3/envs/Financial-Project/lib/python3.7/site-packages/yahoo_fin/stock_info.py in get_live_price(ticker)
    397     '''    
    398 
--> 399     df = get_data(ticker, end_date = pd.Timestamp.today() + pd.DateOffset(10))
    400 
    401 

~/opt/anaconda3/envs/Financial-Project/lib/python3.7/site-packages/yahoo_fin/stock_info.py in get_data(ticker, start_date, end_date, index_as_date, interval)
     86 
     87     # add in adjclose
---> 88     frame["adjclose"] = data["chart"]["result"][0]["indicators"]["adjclose"][0]["adjclose"]
     89 
     90     # get the date info

KeyError: 'adjclose'

´´´
4

2 回答 2

2

苹果代码是“AAPL”(不是“APPL”)。您的代码在该更新下正确运行。

from yahoo_fin import stock_info as si
ab=si.get_live_price('AAPL')
print(ab) 
134.99000549316406
于 2021-02-03T14:37:14.533 回答
1

手册说它不区分大小写,但是您可以使用小写字母来获取它。

from yahoo_fin import stock_info
ab=stock_info.get_live_price('aapl')
print(ab)

129.41000366210938
于 2021-01-05T03:25:07.200 回答