簡體   English   中英

Python Pandas:“ read_table”,不包含標題; 添加列標題,但它們會移動

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

我想為每列添加一個列名,但是當我運行代碼時,它將列標題移到兩列上,並添加了兩列NaN。 是什么原因造成的,並且有更正嗎?

另一個問題; 如何提取沒有列名的特定列? 我正在嘗試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

我想為每列添加一個列名,但是當我運行代碼時,它將列標題移到兩列上,並添加了兩列NaN。 是什么原因造成的,並且有更正嗎?

另一個問題; 如何提取沒有列名的特定列? 我正在嘗試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