0

I'm trying to add names to my columns and indices of a pandas dataframe.

Right now,

Int64Index([2, 4, 5, 32, 112, 344, 543],
          dtype='int64')

is my list of column names. I want to make this such that we have

Int64Index([2, 4, 5, 32, 112, 344, 543],
          dtype='int64', name='mid')

instead, so the 'mid' shows up as a label for the top column.

How do I do this? I tried setting

df.columns=
Int64Index([2, 4, 5, 32, 112, 344, 543],
          dtype='int64', name='mid')

but I got an error that Int64Index is not defined. I don't understand this. How do I just simply add a name to my index?

Kashif
  • 3,063
  • 6
  • 29
  • 45
  • Possible duplicate of [Renaming columns in pandas](https://stackoverflow.com/questions/11346283/renaming-columns-in-pandas) & [dataframe, set index from list](https://stackoverflow.com/questions/39132181/dataframe-set-index-from-list) – Trenton McKinney Oct 09 '19 at 19:09
  • 1
    `df.index.name = 'your_name'`, or `df.columns.name = ...` – ALollz Oct 09 '19 at 19:12

0 Answers0