For some weird reasons I need to get the column names of a dataframe and insert it as the first row(I cannot just import without header). I tried using for comprehension to create a dataframe that only has 1 row and 30 columns(there are 30 headers) and union it to the original dataframe. But what I got is a dataframe with 1 row and only 1 column, with the value being a list of 30 strings.
What I tried:
val headerDF = Seq((for (col <- data.columns) yield col)).toDF
display(headerDF)
Column A |
---|
["col1", "col2", "col3", ...] |
Expected Behavior:
Column A | Column B | Column B |
---|---|---|
col1 | col2 | Col3 |