1

I have a dataset and I am using reset_index to reset the index:

output = output.reset_index(drop=True)

This works properly but I end up with an index column with no label. In other words all of the other columns have labels set, except the first column in the spreadsheet. I would like that index column to have the label "Index".

Thanks!

U13-Forward
  • 69,221
  • 14
  • 89
  • 114
James
  • 55
  • 1
  • 6

3 Answers3

1

Try with rename_axis

output = output.rename_axis('Index')
BENY
  • 317,841
  • 20
  • 164
  • 234
  • This worked for me, thanks! This is how I used it: output = output.reset_index(drop=True).rename_axis('Index') – James Aug 28 '21 at 14:55
0

You could specify the name argument:

output = output.reset_index(name='Index')

output = output.reset_index(name='Index', drop=True)
U13-Forward
  • 69,221
  • 14
  • 89
  • 114
  • Notable that only [`Series.reset_index`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.reset_index.html) has a `name` argument. [`DataFrame.reset_index`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.reset_index.html) does not. – Henry Ecker Aug 28 '21 at 04:11
  • @HenryEcker Yeah! – U13-Forward Aug 28 '21 at 04:14
0

Index label is its attribute. You can change it via an assignment:

output.index.name = "Index"
DYZ
  • 55,249
  • 10
  • 64
  • 93