Skip to content Skip to sidebar Skip to footer

How To Remove The Index Name In Pandas Dataframe?

In my dataframe, I get a '2' written over my index column's name. when I check for the columns name it doesn't show up there but as df.columns give this as output. I don't know how

Solution 1:

you need change the name of columns, not index!

df.columns.name=''

Example to understand it:

df=pd.DataFrame()
df['a']=[1,2,3]
df.columns.name='name column'
df.index.name='name index'df

Output:

name column  a
name index  
011223

Now doing:

df.columns.name=''

Output:

a
name index  
011223

Solution 2:

To modify the DataFrame itself:

df.rename_axis(None, inplace=True)

Post a Comment for "How To Remove The Index Name In Pandas Dataframe?"