how to switch columns rows in a pandas dataframe

后端 未结 2 1329
广开言路
广开言路 2020-11-28 14:52

I have the following dataframe:

                                0       1
0                 enrichment_site   value
1                    last_updated   value         


        
相关标签:
2条回答
  • 2020-11-28 15:04

    You can use df = df.T to transpose the dataframe. This switches the dataframe round so that the rows become columns.

    You could also use pd.DataFrame.transpose().

    0 讨论(0)
  • 2020-11-28 15:05

    When using pd.DataFrame.transpose (as suggested by Jamie Bull / coldspeed), be sure to actually write

    pd.DataFrame.transpose()

    ...without the brackets, it didn't work for me.

    0 讨论(0)
提交回复
热议问题