Warren
Warren

Reputation: 1001

how to drop the title for data-frame columns

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  

Upvotes: 1

Views: 2537

Answers (2)

piRSquared
piRSquared

Reputation: 294258

Option 1
rename_axis

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

Option 2
reassign df.columns

df.columns = df.columns.tolist()

Option 3
Setting the name attribute, as described by Boud.

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

Upvotes: 6

Zeugma
Zeugma

Reputation: 32095

These variables are represented through the name property:

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

Upvotes: 2

Related Questions