我正在尝试根据this post向数据框df
添加新行,但我的语法错误。我错过了什么?
df = pd.DataFrame(columns=['poll1', 'poll2','tval','pval'])
temp = pd.DataFrame([0,0,1,2], columns=['poll1', 'poll2','tval','pval'])
df.append(temp)
print(df)
答案 0 :(得分:0)
df = pd.DataFrame(columns=['poll1', 'poll2','tval','pval'], data=[[0,0,1,2]])
print(df)
或者如果你想使用追加:
cols = ['poll1', 'poll2','tval','pval']
df = pd.DataFrame(columns=cols)
temp = pd.DataFrame(data=[[0,0,1,2]], columns = cols)
df = df.append(temp)
print(df)