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

Pandas 2.0.1中使用append/concat报AttributeError问题求助

Pandas 2.0.1中append替换concat的错误修正

问题根源

Pandas 2.0及以上版本已经移除了DataFrame.append()方法,所以你原代码会触发AttributeError: 'DataFrame' object has no attribute 'append'。

你后续报错AttributeError: 'DataFrame' object has no attribute 'concat',核心问题是**concat不是DataFrame实例的方法**,它属于Pandas模块的顶层函数,必须通过pd.concat()来调用,不能用DataFrame对象直接调用。

正确代码示例

把你的代码修改为以下形式:

import pandas as pd

# 用pd.concat合并两个DataFrame,参数是包含待合并对象的列表
total_device_df = pd.concat(
    [total_device_df, KatsRequest().parse_json_response(filename, device_names)],
    ignore_index=True  # 可选参数,合并后重置索引,避免索引重复冲突
)

重要提示

  • pd.concat()的第一个参数必须是包含所有待合并DataFrame的列表,不能直接传入单个对象
  • 如果两个DataFrame的索引存在重复,建议添加ignore_index=True,这样合并后的DataFrame会生成新的连续索引,避免后续操作出现索引相关问题

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.22 15:34:56