I have some data like this:
ID | Value1 | Value2 | Value40 |
---|---|---|---|
101 | 3 | 520 | 2001 |
102 | 29 | 530 | 2020 |
I want to take this data and convert in to a KV style pair instead
ID | ValueVv | ValueDesc |
---|---|---|
101 | 3 | Value1 |
101 | 520 | Value2 |
101 | 2001 | Value40 |
I think it's a pivot, but I can't think of what this needs to look like in code.
I am trying to solve in PySQL but also in a Python DataFrame as I am using Spark.
I could easily, just union each column into an output using SQL, but I was hoping there is a more efficient way?
I've looked at melt
as an option and stack
. But I'm unsure how to do this effectively.