[英]Add column to pandas without headers
Each not empty DataFrame
has columns
, index
and some values. 每个非空的DataFrame
都有columns
, index
和一些值。
You can add default column value and create new column filled by scalar: 您可以添加默认列值并创建由标量填充的新列:
df[len(df.columns)] = 0
Sample: 样品:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.