python - AttributeError:模块“yahoo_finance”没有属性“下载”
问题描述
import yahoo_finance as yfinance
raw_data = yfinance.download (tickers = "^GSPC ^FTSE ^N225 ^GDAXI", #The time
#series we are interested in - (in our case, these are the S&P, FTSE, NIKKEI and DAX)
start = "1994-01-07", #The starting date of our data set
end = "2019-09-27", #The ending date of our data set (at the time of
# upload, this is the current date)
interval = "1d", #The distance in time between two recorded observations.
#Since we're using daily closing prices, we set it equal
#to "1d", which indicates 1 day.
group_by = 'ticker', #The way we want to group the scraped data. Usually we
#want it to be "ticker", so that we have all the
#information about a time series in 1 variable.
auto_adjust = True, #Automatically adjuss the closing prices for each
# period.
treads = True) #Whether to use threads for mass downloading.
我正在做关于时间序列的 Udemy 课程。并试图访问雅虎金融。但错误如下:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-11-817ad07416bf> in <module>
1 # Using the .download() method to get our data
2
----> 3 raw_data = yfinance.download (tickers = "^GSPC ^FTSE ^N225 ^GDAXI", #The time series we are
interested in - (in our case, these are the S&P, FTSE, NIKKEI and DAX)
4 start = "1994-01-07", #The starting date of our data set
5 end = "2019-09-27", #The ending date of our data set (at the
time of upload, this is the current date)
AttributeError: module 'yahoo_finance' has no attribute 'download'
请帮忙。
解决方案
问题是 yahoo-finance 已被 pandas 弃用。另一种选择是 fix-yahoo-finance 或使用 y-finance。
Anaconda 提示符,输入:
python -m pip install yfinance
pip install fix-yahoo-finance
然后在 Anconda prompt/Pycharmn/Jupyter/Spyder 等中输入:
import yfinance
现在你可以像以前一样继续了。yfinance 有下载选项
推荐阅读
- java - 字段 jdbcTemplate 需要找不到类型为“org.springframework.jdbc.core.JdbcTemplate”的 bean
- logback - 如何通过 App Engine Standard (Java) 在 Logback 上使用 jsonPayload?
- continuous-integration - wercker 中的链式管道(默认执行)不会产生结果
- c - 宏 - 生成 4 位查找表
- c++ - 调暗 vscode 中未使用的变量
- angular - 未捕获的错误:无法解析 HacksStorageService 的所有参数:([object Object],?)。在语法错误
- html - 为整个页面添加噪音
- reactjs - 找不到变量:React Native 的 react-native-material-bottom-navigation 中的选项卡
- c# - NHibernate如何将外键关系映射到多个属性
- python - 了解 Python 堆栈中的递归