附加到 Pandas 中的空数据帧? [英] Appending to an empty DataFrame in Pandas?
本文介绍了附加到 Pandas 中的空数据帧?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以附加到不包含任何索引或列的空数据框?
我尝试过这样做,但最后总是得到一个空的数据框.
例如
将pandas导入为pddf = pd.DataFrame()data = ['这里有某种数据' -->我已经检查了类型,它是一个数据框]df.append(数据)
结果如下:
空数据帧列: []指数: []
解决方案
那应该可行:
<预><代码>>>>df = pd.DataFrame()>>>data = pd.DataFrame({"A": range(3)})>>>df.append(数据)一种0 01 12 2但是append
不会就地发生,因此如果需要,您必须存储输出:
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.
e.g.
import pandas as pd
df = pd.DataFrame()
data = ['some kind of data here' --> I have checked the type already, and it is a dataframe]
df.append(data)
The result looks like this:
Empty DataFrame
Columns: []
Index: []
解决方案
That should work:
>>> df = pd.DataFrame()
>>> data = pd.DataFrame({"A": range(3)})
>>> df.append(data)
A
0 0
1 1
2 2
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 中的空数据帧?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文