I have a spark data frame df. Is there a way of sub selecting a few columns using a list of these columns?
df
scala> df.columns res0: Array[Stri
You can pass arguments of type Column* to select:
Column*
select
val df = spark.read.json("example.json") val cols: List[String] = List("a", "b") //convert string to Column val col: List[Column] = cols.map(df(_)) df.select(col:_*)