如何删除数据框列的标题 [英] how to drop the title for data-frame columns
本文介绍了如何删除数据框列的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想出了一个这样的数据框,我想知道如何才能更改或删除"id"和"date",因为它们只是索引和列的名称.
I come up with a dataframe like this, I wonder how can we change or drop the 'id' and 'date' as they are just the names for index and columns.
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
推荐答案
选项1
rename_axis
df.rename_axis(None, 1, inplace=True) # 1 is for axis=1
选项2
重新分配df.columns
Option 2
reassign df.columns
df.columns = df.columns.tolist()
选项3
设置name
属性,如Boud 所述.
Option 3
Setting the name
attribute, as described by Boud.
df.columns.name = None
df.index.name = None
这篇关于如何删除数据框列的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文