简体   繁体   English

Python Pandas:“ read_table”,不包含标题; 添加列标题,但它们会移动

[英]Python Pandas: 'read_table' with no header; adding column headers but they shift

I want to add a column name for each column but when I ran the code it shifted my column heading over two columns and added a two columns of NaN.我想为每列添加一个列名,但是当我运行代码时,它将列标题移到两列上,并添加了两列NaN。 What is causing this and is there a correction?是什么原因造成的,并且有更正吗?

Another question;另一个问题; how do you pull a particular column with no columns names?如何提取没有列名的特定列? I was trying df[0] (1,2, etc) but I receive an error.我正在尝试df [0](1,2等),但收到错误消息。

df = pd.read_table('numcyc.dat', header=None, names = df_cols)
print(df)
                        place  loc  time
0          3      111.1    44  NaN   NaN
1          3      111.1    34  NaN   NaN
2          4      111.1    23  NaN   NaN
3          2      111.1    16  NaN   NaN

I want to add a column name for each column but when I ran the code it shifted my column heading over two columns and added a two columns of NaN.我想为每列添加一个列名,但是当我运行代码时,它将列标题移到两列上,并添加了两列NaN。 What is causing this and is there a correction?是什么原因造成的,并且有更正吗?

Another question;另一个问题; how do you pull a particular column with no columns names?如何提取没有列名的特定列? I was trying df[0] (1,2, etc) but I receive an error.我正在尝试df [0](1,2等),但收到错误消息。

df = pd.read_table('numcyc.dat', header=None, names = df_cols)
print(df)
                        place  loc  time
0          3      111.1    44  NaN   NaN
1          3      111.1    34  NaN   NaN
2          4      111.1    23  NaN   NaN
3          2      111.1    16  NaN   NaN

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM