0

I have a spark dataframe

inputDF: org.apache.spark.sql.DataFrame = [_id: string, Frequency:              double, Monterary: double, Recency: double, CustID: string]
        root
     |-- _id: string (nullable = false)
     |-- Frequency: double (nullable = false)
     |-- Monterary: double (nullable = false)
     |-- Recency: double (nullable = false)
     |-- CustID: string (nullable = false)

I want to create a new dataframe by dropping string columns from this. Specific condition is not to iterate over the column names . Anyone has any idea ?

1 Answer 1

4

If schema is flat and contains only simple types you can filter over fields but unless you have a crystal ball you cannot really avoid iteration:

import org.apache.spark.sql.types.StringType
import org.apache.spark.sql.functions.col

df.select(df.schema.fields.flatMap(f => f.dataType match {
  case StringType => Nil
  case _ => col(f.name) :: Nil
}): _*)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.