Home > database >  How to transpose rows into columns in python?
How to transpose rows into columns in python?

Time:06-01

my data

Hello, i would like to transform/transpose this DF into an other DF with one row containing all the columns: for exemple i will have columns GearLeverPosition_v2_count, GearLeverPosition_v2_mean ... with the index 0 having the values for each one. IF you guys can help me it would be great thanks !

CodePudding user response:

Same as in numpy, to transpose a DataFrame in pandas you can:

df.T

or equivalently:

df.transpose()

CodePudding user response:

You can use transpose() function to transpose index and columns. Reflect the DataFrame over its main diagonal by writing rows as columns and vice-versa.

CodePudding user response:

There's a transpose function in pandas

https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.transpose.html?highlight=transpose#pandas.DataFrame.transpose

  • Related