Scala Spark-> Select first 15 columns from a DataFrame

Viewed 136

I am trying to get the first 15 columns from a DataFrame that contains more than 500 cols. But I don't know how to do it because is my first time using Scala Spark.

I was searching but didn't find anything, just how to get cols by name, for example:

val df2 = df.select("firstColName", "secondColeName")

How can i do this by index?

Thanks in advance!

1 Answers

Scala example:

df.selectExpr(df.columns.take(15):_*)
Related