2

How to pass DataFrame cc into Array[Seq[String]]?

val factors = $(ccCols).split(",")
val cc = dataset.select(factors.head, factors.tail: _*)

I tried this way, but it gives me Array[Row]:

cc.rdd.collect()

1 Answer 1

5

You will need to use the toSeq function of the Row object:

val a = sc.parallelize(Seq((1,2),(3,4))).toDF("a", "b")
a.show
/*
Output:
+-+-+
|a|b|
+-+-+
|1|2|
|3|4|
+-+-+
*/

a.collect.map(_.toSeq)
// Output: Array(WrappedArray(1, 2), WrappedArray(3, 4))
Sign up to request clarification or add additional context in comments.

2 Comments

It's now Array[Seq[Ahy]]. How to substitute Any by String?
I think a a.collect.map(_.toSeq.map(_.toString)) would do it

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.