2

I have the following data frame with itemid column is bold when printed in the notebook.

itemid | user_id | day1 | day2 0 | 1232 | 5 | 3 1 | 4107 | 5 | 3 2 | 9262 | 5 | 3 3 | 1031 | 5 | 3 

Then I reset the its index using this:

df.index.name = None 

But, then I still have the same dataframe. Then, I reset its index using:

df= df.set_index('user_id') 

Then, I get this:

item_id | day1 | day2 user_id 1232 | 5 | 3 4107 | 5 | 3 9262 | 5 | 3 1031 | 5 | 3 

I have no idea why item_id still stays there. Any ideas?

1 Answer 1

2

The itemid is the name of your columns, you can try:

df.columns.name = None 
Sign up to request clarification or add additional context in comments.

3 Comments

IThanks for the answer! is this going to destroy all the column names? I would not prefer because I need them.
No. The column headers still stay. It's just the name of your columns headers will be removed. And you will get a data frame whose index has no name when you stack your data frame.
Yes df.columns gives the column index or columns headers which are the names of all the columns. But all the columns headers have another name attribute which is the one you are trying to remove here.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.