I am looking for an efficient way to take the headers of several columns, and unpivot them into a single column. Here is an example:
I start with a table that looks like this. Three columns, one header for each of them.
| Header 1| Header 2| Header 3 |
___________________________________
| null | null | null |
| null | null | null |
| null | null | null |
What I want to do is this ->
| Some Name | Unique Name | Unique Name | Unique Name
_______________________________________________________
| Header 1 | null | null | null
| Header 2 | null | null | null
| Header 3 | null | null | null
I'm essentially attempting to transpose the Header names in each column to become their own values in a single column, which will receive a new header name. Each value in the row will also be a part of a new column which will receive a new header name. I understand how to take a column and use .pivot()
function to create new headers based on the values of a column, but I've had trouble doing the reverse.
My research has shown that Python has .melt()
which may or may not be the ideal solution to this problem, but being a new Scala developer and using Spark for the first time - I could use some advice for how to best approach this. My apologies if this is more simple than I imagine it to be!
Thank you for all of your assistance.