运行Python股票查询代码遇frame.append废弃警告,如何适配?
解决pandas frame.append弃用警告的方案
你的代码本身没有直接调用frame.append方法,这个警告来自你使用的yahoo_fin库内部——它的源码里用到了pandas已被弃用的append方法。以下是几种处理方案:
方案1:临时忽略警告
如果不影响代码功能,只是不想看到警告,可以在代码开头添加过滤警告的代码:
import os import warnings # 过滤指定的FutureWarning warnings.filterwarnings("ignore", category=FutureWarning, message="The frame.append method is deprecated.*") 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
方案2:等待库更新
这个问题属于yahoo_fin库的内部代码适配问题,你可以关注该库的更新,等开发者发布新版本将内部的append替换为pandas.concat后,升级库即可解决。
方案3:手动修改库源码(进阶操作)
如果你想立即解决,可以找到yahoo_fin库的安装目录,定位到使用append的代码文件(通常是处理数据拼接的模块),将类似df.append(other_df)的代码替换为pd.concat([df, other_df], ignore_index=True)。
注意:手动修改库源码会影响全局使用,更新库后修改会被覆盖,谨慎操作。
内容的提问来源于stack exchange,提问作者Stranger
相关产品推荐
相关产品推荐

