0

I am trying to take the index of a dataframe and swap it with the column header names.

For example:

Index Header1 Header2 Header3                    Index   0  1  2  3

0                                                Header1

1                                       ===>     Header2

2                                                Header3

3
febreeze
  • 45
  • 6
  • Are you looking to something similar to this ? https://stackoverflow.com/questions/6473679/transpose-list-of-lists – mandrewcito Feb 16 '20 at 22:35

2 Answers2

2

See DataFrame.T, which will swap the rows and columns.

Lewis
  • 4,285
  • 1
  • 23
  • 36
2

If you just want to swap the labels without transposing the values in the dataframe (assuming it is square):

df.index, df.columns = df.columns, df.index
Alexander
  • 105,104
  • 32
  • 201
  • 196