问题描述
如果我这样有一个空的数据框:
If I have an empty dataframe as such:
columns = ['Date', 'Name', 'Action','ID']
df = pd.DataFrame(columns=columns)
是否可以将新行追加到此新创建的数据框?当前,我必须创建一个字典,将其填充,然后将字典附加到最后的数据框中.有没有更直接的方法?
is there a way to append a new row to this newly created dataframe? Currently I have to create a dictionary, populate it, then append the dictionary to the dataframe at the end. Is there a more direct way?
推荐答案
即将发布的pandas 0.13版本将允许通过loc
在不存在的索引数据上添加行.但是,请注意,这实际上会创建整个DataFrame的副本,因此这不是有效的操作.
Upcoming pandas 0.13 version will allow to add rows through loc
on non existing index data. However, be aware that under the hood, this creates a copy of the entire DataFrame so it is not an efficient operation.
说明位于此处,并且此新功能称为放大设置.
Description is here and this new feature is called Setting With Enlargement.
这篇关于如何向 pandas 数据框添加额外的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!