0

I have to add multiple column to the existing dataframe without any static value. I tried with withColumn dataframe.withColumn(c,col(c)) but I have more than 10 columns to add. How can I do that ?

3
  • what will be the values for those columns ? Commented Mar 20, 2017 at 7:21
  • Seq(col1,col2,col3 ... col10).foldLeft(ds)((acc,c) => acc.withColumn(c,col(c)))??? Commented Mar 20, 2017 at 9:01
  • Yes @AndrzejJozwik I am looking something like that. Commented Mar 20, 2017 at 9:44

1 Answer 1

4
import org.apache.spark.sql._

val newDs:DataFrame =Seq("col1","col2","col3").foldLeft[DataFrame](ds)(
     (acc,c) => 
          acc.withColumn(c,col(c))
     )
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.