gpt4 book ai didi

python - 属性错误 : module 'yfinance' has no attribute 'download'

转载 作者:行者123 更新时间:2023-12-05 06:17:39 59 4
gpt4 key购买 nike

我正在尝试将 yfinance 和一些股票导入 pandas 数据框。最初在导入 yfinance 时遇到了重大问题。我使用 pip 安装,但仍然必须手动放入文件才能真正摆脱无模块错误。

到目前为止,这是我的代码:

现在我在尝试下载 yfinance 时遇到属性错误。

import pandas as pd
import datetime as dt
import yfinance as yf
# import fix_yahoo_finance as yf

stocks = ["AMZN", "MSFT", "INTC", "GOOG", "INFY.NS", "3988.HK"]
start = dt.datetime.today()- dt.timedelta(30)
end = dt.datetime.today()
cl_price = pd.DataFrame()

for ticker in stocks:
cl_price[ticker] = yf.download(ticker,start,end)["Adj Close"]

这是错误:

AttributeError                            Traceback (most recent call last)
<ipython-input-51-3347ed0c7f2b> in <module>
10
11 for ticker in stocks:
---> 12 cl_price[ticker] = yf.download(ticker,start,end)["Adj Close"]

AttributeError: module 'yfinance' has no attribute 'download'

我尝试了 AttributeError: module 'yahoo_finance' has no attribute 'download' 的建议但还是不行

感谢任何解决方案

最佳答案

我刚刚遇到了同样的错误,但在删除名为 yahoofinance 的本地文件后,以下代码有效

!pip install yfinance
import yfinance as yf
import pandas as pd
import datetime as dt

关于python - 属性错误 : module 'yfinance' has no attribute 'download' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61509917/

59 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com