python · pandas |(已解决)AttributeError: 'DataFrame' object has no attribute 'append'


python,pandas,使用 dataframe,debug 记录。

(因为已经报过很多次这个错,所以把解决方案记到博客上)


报错信息:

AttributeError: 'DataFrame' object has no attribute 'append'

原先的代码:

df = pd.DataFrame(df).append({'key1': 123, 'key2': 234}, ignore_index=True)

报错原因:pandas 库 2.0 及以后的版本把 append() 方法删除了。

修改后的代码:

df.loc[len(df)] = {'key1': 123, 'key2': 234}


posted @ 2024-06-23 15:39  MoonOut  阅读(35)  评论(0编辑  收藏  举报