Search code examples
python-3.xpandasreshapereindex

Data frame index transformation in Pandas


I want to trasnform the following data frame:

 ID 1234
     type   band    category
  0    A      B       C

to:

ID     type   band   category
1234     A      B      C

where ID is the index column


Solution

  • Try

    df.stack(0).reset_index().drop('level_0', axis=1)
    

    Output:

         ID Type band category
    0  1234    A    B        C