【发布时间】:2025-11-27 23:30:02
【问题描述】:
我曾尝试从雅虎财经下载市场数据,但一直出错。这是我的代码:
import yfinance as yf
#import data of different asset classes
VT = yf.download("VT",interval="1d", start="2017-01-01", end="2021-01-01") #stocks
BND = yf.download("BND",interval="1d", start="2017-01-01", end="2021-01-01") #bonds
VNQ = yf.download("VNG",interval="1d", start="2017-01-01", end="2021-01-01") #real estate
DBC = yf.download("DBC",interval="1d", start="2017-01-01", end="2021-01-01") #commodities
出现此错误:
KeyboardInterrupt Traceback (most recent call last)
<ipython-input-3-2a474e2089b7> in <module>
1 #import data of different asset classes
----> 2 VT = yf.download("VT",interval="1d", start="2017-01-01", end="2021-01-01") #stocks
3 BND = yf.download("BND",interval="1d", start="2017-01-01", end="2021-01-01") #bonds
4 VNQ = yf.download("VNG",interval="1d", start="2017-01-01", end="2021-01-01") #real estate
5 DBC = yf.download("DBC",interval="1d", start="2017-01-01", end="2021-01-01") #commodities
~/anaconda3/lib/python3.7/site-packages/yfinance/multi.py in download(tickers, start, end, actions, threads, group_by, auto_adjust, back_adjust, progress, period, interval, prepost, proxy, rounding, **kwargs)
93 rounding=rounding)
94 while len(shared._DFS) < len(tickers):
---> 95 _time.sleep(0.01)
96
97 # download synchronously
KeyboardInterrupt:
【问题讨论】:
-
当前版本好像有各种问题。在我的环境中,使用最新版本(0.62.1),没有错误。
-
请问有没有其他下载市场数据的方式可能比雅虎财经更好?
-
我敢肯定还有像yahoo_fin、yahooquery、pandas-datareader这样的人,但我个人推荐yfinance。
标签: python yahoo-finance