You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Pandas拼接空DataFrame与现有DataFrame触发TypeError问题排查

问题原因及解决办法
  • 错误核心:你调用pd.concat()时,传入的是字符串"historical_df"和"result",而非实际的DataFrame对象。pd.concat仅接受Series或DataFrame实例作为拼接元素,字符串不属于合法类型,因此触发类型错误。
  • 额外注意:你提到第二个DataFrame名为result_df,但代码里写的是"result",这里大概率是笔误,必须保证传入的变量名和实际定义的一致。

正确拼接代码

historical_df = pd.concat([historical_df, result_df], axis=0, ignore_index=True)

可选验证步骤

如果仍有疑问,可在拼接前确认对象类型,排除变量名混淆问题:

# 验证对象类型
print(type(historical_df))  # 预期输出:<class 'pandas.core.frame.DataFrame'>
print(type(result_df))     # 预期输出:<class 'pandas.core.frame.DataFrame'>

内容的提问来源于stack exchange,提问作者Para

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 16:27:00