frame.append()方法已弃用


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问题。

stock_info.py的第295、302和336行似乎是源代码中的问题所在。我已经打开了一个拉请求来解决这个问题。有问题的行如下:
data = tables[0].append(tables[1])

我的PR把它们改成了这个

data = pd.concat([tables[0], tables[1]])

可以修复这个问题。如果您没有耐心,不能等待上游合并PR,那么您可以自己应用补丁并从源代码构建。

我从未使用过yahoo_fin,但根据您的代码和有问题的警告,这似乎是该库的开发人员需要更改的东西(通过使用concat方法而不是append)。与此同时,你可以继续使用它,忽略警告,或者你可以一直贡献到他们的代码库,或者分叉它,为自己做改变。

最新更新