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

后端 未结 7 1128
隐瞒了意图╮
隐瞒了意图╮ 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:26

    You can typecast String to spark column like this:

    import org.apache.spark.sql.functions._
    df.select(cols.map(col): _*)
    

提交回复
热议问题