如何删除数据框列的标题

时间:2016-11-22 18:48:56

标签: python pandas

我想出了这样一个数据帧,我想知道我们怎样才能更改或删除“id”#。和' date'因为它们只是索引和列的名称。

id               col1        col2       clo3  
date                                          
2000-01-03  55.500000         NaN        NaN  
2000-01-04  52.812500         NaN        NaN  
2000-01-05  52.750000         NaN        NaN  
2000-01-06  53.500000         NaN        NaN  
2000-01-07  53.625000         NaN        NaN  
2000-01-10  52.656250         NaN        NaN  

2 个答案:

答案 0 :(得分:7)

选项1
rename_axis

df.rename_axis(None, 1, inplace=True)  # 1 is for axis=1

选项2
重新分配df.columns

df.columns = df.columns.tolist()

选项3
name属性设置为described by Boud

df.columns.name = None
df.index.name = None

答案 1 :(得分:3)

这些变量通过name属性表示:

df.columns.name = None
df.index.name = None