I want 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.
-
could you add in the question an example of the desired result. looks like you want a vector containing metrics (count, mean) for each column. Is that right?user2261062– user22610622022-06-01 08:49:27 +00:00Commented Jun 1, 2022 at 8:49
-
yeah it's right i want only one raw and a lot of columnsJahd Jabre– Jahd Jabre2022-06-01 08:58:48 +00:00Commented Jun 1, 2022 at 8:58
-
then you don't want to transpose it. you are getting several answers that tell you how to transpose, since it's what you asked in the title.user2261062– user22610622022-06-01 10:20:22 +00:00Commented Jun 1, 2022 at 10:20
Add a comment
|
4 Answers
Same as in numpy, to transpose a DataFrame in pandas you can:
df.T
or equivalently:
df.transpose()
4 Comments
Jahd Jabre
df.transpose() doesnt make it, i've already tried, i want to transform the whole data frame with one line and severals columns. my final df should have 8 columns having GearLeverPosition_v2 + prefix, same for other columns.
Jahd Jabre
for now i have 226 columns, i want one line with 226 x 8 columns
Piotr
Right, then you mean a pivot table
Jahd Jabre
i tried with valueError : no groupe keys passed –
There's a transpose function in pandas
2 Comments
Tyler2P
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes.
Nick Vence
Posts should answer the question directly (in writing) rather than indirectly (in a link). Would you consider removing this post so it doesn't separate the actual answer (below) away from the question?
