python - yFinance 多股票代码信息不起作用
问题描述
我无法通过 yFinance 获取多行情信息。我想建立多股票代码方法,而不是单独遍历每只股票,这样我就可以使用会话功能并提高性能。
我使用 yfinance 0.1.63 和 python 364。
我的代码是这个
import yfinance as yf
tickers = yf.Tickers('msft aapl goog')
print(tickers.tickers.GOOG.actions)
print(tickers.tickers.AAPL.history(period="1mo"))
print(tickers.tickers.MSFT.info)
但我的输出是这样的
Traceback (most recent call last):
File "C:\opt\jobs\python\multitech.py", line 32, in <module>
print(tickers.tickers.GOOG.actions)
AttributeError: 'dict' object has no attribute 'GOOG'
这似乎对其他人有用,但对我不起作用
解决方案
我遇到了同样的问题。花了一些时间四处寻找,但想出了解决方案。在 Anaconda 包下使用 python 3.8 和 yfinance 0.1.63。
import yfinance as yf
tickers = yf.Tickers('msft aapl goog')
print(tickers.tickers['GOOG'].actions)
print(tickers.tickers['AAPL'].history(period="1mo"))
print(tickers.tickers['MSFT'].info)
推荐阅读
- php - MySQL,无效的日期时间格式:1366 不正确的整数值:“iRecipes”列的“”。“搜索”。“id”(php)
- c++ - 如何同时对两个或三个数组进行排序?
- c - 加速 for 循环,(动态)约束索引
- angular - 编写多个测试用例时,ActivatedRoute 参数在单元测试中不起作用
- curl - 我想卷曲,但它重定向到本地主机
- reactjs - React - 在生产文件中隐藏环境变量
- android-layout - Android项目按钮导航活动片段上边距
- c - 堆栈为节点数组
- python - Python猴子修补类方法导致多处理错误
- c# - 从 ASP.Net Core Web API 记录到 Eventlog 失败