Scala Spark DataFrame : dataFrame.select multiple columns given a Sequence of column names

后端 未结 2 1257
半阙折子戏
半阙折子戏 2020-12-08 02:51
val columnName=Seq(\"col1\",\"col2\",.....\"coln\");

Is there a way to do dataframe.select operation to get dataframe containing only the column na

2条回答
  •  离开以前
    2020-12-08 03:20

    val columnNames = Seq("col1","col2",....."coln")
    
    // using the string column names:
    val result = dataframe.select(columnNames.head, columnNames.tail: _*)
    
    // or, equivalently, using Column objects:
    val result = dataframe.select(columnNames.map(c => col(c)): _*)
    

提交回复
热议问题