将列添加到没有标题的 pandas [英] Add column to pandas without headers
本文介绍了将列添加到没有标题的 pandas 的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将一列常量值追加到不带标题的pandas数据框中?我想在该列的末尾追加.
How does one append a column of constant values to a pandas dataframe without headers? I want to append the column at the end.
推荐答案
Each not empty DataFrame
has columns
, index
and some values.
您可以添加默认列值并创建由标量填充的新列:
You can add default column value and create new column filled by scalar:
df[len(df.columns)] = 0
示例:
df = pd.DataFrame({0:[1,2,3],
1:[4,5,6]})
print (df)
0 1
0 1 4
1 2 5
2 3 6
df[len(df.columns)] = 0
print (df)
0 1 2
0 1 4 0
1 2 5 0
2 3 6 0
还可以使用最简单的名称创建新列:
Also for creating new column with name the simpliest is:
df['new'] = 1
这篇关于将列添加到没有标题的 pandas 的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文