-1

I want to use graphX in zeppelin with my dataframe

First, my dataframe is as below.

+---+-----+---+
| id| name|age|
+---+-----+---+
|  a|   AA| 34|
|  b|   BB| 36|
|  c|   CC| 30|
|  d|   DD| 29|
|  e|   EE| 32|
|  f|   FF| 36|
|  g|   GG| 60|
+---+-----+---+

So I want to convert this dataframe to RDD as below.

RDD[(id, (name, age))]

But I don't know how can I convert it.

1 Answers1

0

Use .rdd as below:

val result = df.rdd.map(row => (row(0).asInstanceOf[Int], (row(1).asInstanceOf[String], row(2).asInstanceOf[String])))
mck
  • 40,932
  • 13
  • 35
  • 50