Python 将行附加到 Pandas DataFrame 而不制作新副本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18196616/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Append rows to a pandas DataFrame without making a new copy
提问by cameron.bracken
The pandas documentationincludes a note:
pandas文档包括一个注释:
Note Unlike list.append method, which appends to the original list and returns nothing, append here does not modify df1 and returns its copy with df2 appended.
注意 与 list.append 方法附加到原始列表并且不返回任何内容不同,这里的 append 不会修改 df1 并返回其附加了 df2 的副本。
How can I append to an existing DataFrame without making a copy? Or in the terms of the note how can I modify df1 in place by appending df2 and return nothing?
如何在不制作副本的情况下附加到现有的 DataFrame?或者根据注释,如何通过附加 df2 来修改 df1 并且不返回任何内容?
回答by mattexx
Why not use concat?
为什么不使用 concat?
df = pd.concat([df, pd.DataFrame(new_data)])
回答by Nasser Al-Wohaibi
See How to add an extra row to a pandas dataframe
Upcoming pandas 0.13 version will allow to add rows through loc
on non existing index data.
即将推出的 pandas 0.13 版本将允许loc
在不存在的索引数据上添加行。
Description is hereand this new feature is called Setting With Enlargement.
描述在这里,这个新功能叫做Setting With Enlargement。