0

I have this dataframe

enter image description here

For some reason when I did this all_data = all_data.set_index(['Location+Type']) the name 'Location+Type' is now gone. How do I now set the first column of the dataframe to have the name 'Location+Type'?

2
  • all_data.index.name = 'Location+Type' helps? Commented Dec 13, 2019 at 18:41
  • If it doesn't show the index name after calling set_index, there's a bug somewhere or something is wrong. Commented Dec 13, 2019 at 19:02

1 Answer 1

1

By using set_index(['Location+Type']) you no longer have the column Location+Type instead, it is now the index of your dataframe therefore when printing, you are not seeing the name. If you wish to recover Location+Type as a column, then you need to use:

all_data = all_data.reset_index() 

This will create a new index, while returning the original index (Location+Type) to a column. As the documentation states:

When we reset the index, the old index is added as a column, and a new sequential index is used:

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.