How to switch columns rows in a pandas dataframe

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().

Leave a Comment