1

Hi I was wondering if anyone could please tell me how to set the "index name" in the same axis as the column names in a data frame. In the image below, I am trying to put the word "count" on the same line as the column headers. Any help would be greatly appreciated.

enter image description here

3
  • 2
    It's already named. If you do df2.reset_index() it will be at the same level as the column headers (it will become a column) Commented Sep 21, 2018 at 15:22
  • You are looking for df2.columns.name='count' Commented Sep 21, 2018 at 15:24
  • df2.rename_axis('count', axis=1) or df2,columns.name = "count" Commented Sep 21, 2018 at 18:37

1 Answer 1

1

Take a look at this doc: http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.rename_axis.html

df2.index.name = None
df2.rename_axis("count", axis="columns", inplace=True)

As Wen said in the comment, it's same with adding a name to the "column header".

df2.columns.name = "count"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.