MLstudent
MLstudent

Reputation: 89

Scala Spark-> Select first 15 columns from a DataFrame

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!

Upvotes: 1

Views: 226

Answers (1)

falcon-le0
falcon-le0

Reputation: 609

Scala example:

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

Upvotes: 4

Related Questions