import os
import yahoo_fin.stock_info as si
tickers = ["aapl","msft","fb"]
for ticker in tickers:
try:
quote = si.get_quote_table(ticker)
price = (quote["Quote Price"])
print (ticker, price)
except:
pass
当运行这段代码时,我得到这个错误:
FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
谁能告诉我如何调整代码?
因为您没有使用pandas,所以这看起来像是yahoo_fin
模块的问题。这里有一个公开的GitHub问题。
data = tables[0].append(tables[1])
我的PR把它们改成了这个
data = pd.concat([tables[0], tables[1]])
可以修复这个问题。如果您没有耐心,不能等待上游合并PR,那么您可以自己应用补丁并从源代码构建。
我从未使用过yahoo_fin
,但根据您的代码和有问题的警告,这似乎是该库的开发人员需要更改的东西(通过使用concat
方法而不是append
)。与此同时,你可以继续使用它,忽略警告,或者你可以一直贡献到他们的代码库,或者分叉它,为自己做改变。