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.
1 Answer
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"

df2.reset_index()it will be at the same level as the column headers (it will become a column)df2.rename_axis('count', axis=1)ordf2,columns.name = "count"