更新到 Pandas 1.4 后,当使用 frame.append 将字典附加到 Pandas DataFrame 时,我现在会收到以下警告。
FutureWarning: The frame.append method is deprecated and will be
removed from pandas in a future version. Use pandas.concat instead.
以下是代码。虽然我想解决警告,但这仍然有效。
report = report.append({
"period":period,
"symbol":symbol,
"start_date":start_date,
"start_price":start_price,
"start_market_cap":start_market_cap,
"end_date":end_date,
"end_price":end_price,
"end_market_cap":end_market_cap,
"return":return_
},ignore_index=True)
我已更新代码如下,会提示另一个警告:
report = pd.concat([report,{
"period":period,
"symbol":symbol,
"start_date":start_date,
"start_price":start_price,
"start_market_cap":start_market_cap,
"end_date":end_date,
"end_price":end_price,
"end_market_cap":end_market_cap,
"return":return_
}],ignore_index=True)
TypeError: cannot concatenate object of type '<class 'dict'>'; only Series and DataFrame objs are valid
两个问题: 第一个警告是错的吗? 如何使用 pandas 1.4 实现这个功能? 谢谢。