Upacking a list to select multiple columns from a spark data frame

后端 未结 7 1112
隐瞒了意图╮
隐瞒了意图╮ 2020-12-07 14:03

I have a spark data frame df. Is there a way of sub selecting a few columns using a list of these columns?

scala> df.columns
res0: Array[Stri         


        
7条回答
  •  囚心锁ツ
    2020-12-07 14:29

    Yes , You can make use of .select in scala.

    Use .head and .tail to select the whole values mentioned in the List()

    Example

    val cols = List("b", "c")
    df.select(cols.head,cols.tail: _*)
    

    Explanation

提交回复
热议问题