从雅虎财经下载市场数据时出错
Posted
技术标签:
【中文标题】从雅虎财经下载市场数据时出错【英文标题】:Error when downloading market data from yahoo finance 【发布时间】:2021-07-10 13:50:35 【问题描述】:我曾尝试从雅虎财经下载市场数据,但一直出错。这是我的代码:
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。 【参考方案1】:试试这个:
import datetime as dt
import pandas as pd
import yfinance as yf
from pandas_datareader import data as pdr
tickers = ["AAPL","GOOG","AMZN"]
yf.download(tickers, start = "2021-02-01" , end = "2021-02-04")
【讨论】:
以上是关于从雅虎财经下载市场数据时出错的主要内容,如果未能解决你的问题,请参考以下文章