Skip to content
Advertisement

How to transpose a dataframe in pyspark?

How do I transpose columns in Pyspark? I want to make columns become rows, and rows become the columns.

Here is the input:

JavaScript

Expected Outcome:

JavaScript

Advertisement

Answer

You can combine stack function to unpivot vin, mean and cur columns then pivot column idx:

JavaScript

You apply the transformation one by one to see how it works and what do each part.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement