0

I have a pandas data frame like this

variable    id Max
0   8004    5
1   8005    10
2   8006    9
3   8034    14
4   8046    3

if I check the df.columns I get

Index(['id', 'Max'], dtype='object', name='variable')

But I dont care the variable, I want to keep the information in the index but that appears as columns and delete the variable. I don't know if it is important, but I get the dataframe by pivoting another table.

LizUlloa
  • 172
  • 3
  • 9

1 Answers1

0

Use pandas.DataFrame.rename_axis with None as the argument:

import pandas as pd

df = pd.DataFrame(dict(
    variable = [0, 1, 2, 3, 4],
    id = [8004, 8005, 8006, 8034, 8046],
    Max = [5, 10, 9, 14, 3],
)).set_index('variable')

df = df.rename_axis(None)

Python Tutor link to example

Phillyclause89
  • 674
  • 4
  • 12