【发布时间】:2013-05-11 22:14:19
【问题描述】:
是否可以追加到不包含任何索引或列的空数据框?
我尝试过这样做,但最后总是得到一个空数据框。
例如
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)
结果如下:
Empty DataFrame
Columns: []
Index: []
【问题讨论】:
-
在这里回答了类似的问题:stackoverflow.com/questions/13784192/…。基本上是这样的
newDF = pd.DataFrame() #creates a new dataframe that's empty newDF = newDF.append(oldDF, ignore_index = True) # ignoring index is optional -
追加什么?单一价值? Python 列表?熊猫系列?另一个数据框? 您的示例尾随注释表明您的意思是另一个数据框 - 所以在您的示例代码中给出一个数据框,已经:)
-
当你说“结果看起来像这样”时,我希望你不要直接尝试做
print(df.append(data)),因为append()always returns None in Python