追加到Pandas中的一个空DataFrame吗? [英] Appending to an empty DataFrame in Pandas?
本文介绍了追加到Pandas中的一个空DataFrame吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以将其追加到不包含任何索引或列的空数据框中?
Is it possible to append to an empty data frame that doesn't contain any indices or columns?
我已经尝试过这样做,但是最后总是得到一个空的数据框.
I have tried to do this, but keep getting an empty dataframe at the end.
例如
df = pd.DataFrame()
data = ['some kind of data here' --> I have checked the type already, and it is a dataframe]
df.append(data)
结果如下:
Empty DataFrame
Columns: []
Index: []
推荐答案
应该有效:
>>> df = pd.DataFrame()
>>> data = pd.DataFrame({"A": range(3)})
>>> df.append(data)
A
0 0
1 1
2 2
但是 append
不能就地发生,因此,如果需要,您必须存储输出:
But the append
doesn't happen in-place, so you'll have to store the output if you want it:
>>> df
Empty DataFrame
Columns: []
Index: []
>>> df = df.append(data)
>>> df
A
0 0
1 1
2 2
这篇关于追加到Pandas中的一个空DataFrame吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文