How to merge two columns of a `Dataframe` in Spark into one 2-Tuple?

后端 未结 4 1974
野趣味
野趣味 2020-12-14 22:14

I have a Spark DataFrame df with five columns. I want to add another column with its values being the tuple of the first and second columns. When u

4条回答
  •  佛祖请我去吃肉
    2020-12-14 23:00

    You can merge multiple dataframe columns into one using array.

    // $"*" will capture all existing columns
    df.select($"*", array($"col1", $"col2").as("newCol")) 
    

提交回复
热议问题