1

I want to change the column index name

here the column index name (To be more preceise, sequence name) is 'Data Field':-

enter image description here

To a new sequence name, may be Column1, but when I'm doing

df.index.name = 'Column1'

It's adding Column1 at the bottom of the previous column index name. Which I don't want

enter image description here

Rajdip Roy
  • 21
  • 2

3 Answers3

0

You can give df.rename(columns={}) to replace a specific column name.

df.rename(columns={'old column name':'new column name'}, inplace=True)

In your specific case, looks like you want to rename Data Field. You can give:

df.rename(columns={'Data Field': 'Column1'},inplace=True)
Joe Ferndz
  • 8,417
  • 2
  • 13
  • 33
0
df.rename(columns={'Data Field': 'Column1'},inplace=True)
berkayln
  • 935
  • 1
  • 8
  • 14
  • 1
    It's not the name of the column, we cannot access it with df.columns, it's more like the sequence name, which appears on the left most side of the columns – Rajdip Roy Mar 23 '21 at 16:47
0
df.columns = df.columns.rename("Column1", level=0)
Laurent
  • 12,287
  • 7
  • 21
  • 37