我正在尝试将 RDD 转换为 pyspark 中的 Dataframe。
My RDD:
[(['abc', '1,2'], 0), (['def', '4,6,7'], 1)]
我想要 Dataframe 形式的 RDD:
Index Name Number
0 abc [1,2]
1 def [4,6,7]
我试过:
rd2=rd.map(lambda x,y: (y, x[0] , x[1]) ).toDF(["Index", "Name" , "Number"])
但我收到错误
An error occurred while calling
z:org.apache.spark.api.python.PythonRDD.runJob.
: org.apache.spark.SparkException: Job aborted due to stage failure:
Task 0 in stage 62.0 failed 1 times, most recent failure: Lost task 0.0
in stage 62.0 (TID 88, localhost, executor driver):
org.apache.spark.api.python.PythonException: Traceback (most recent
call last):
你能告诉我,我哪里出错了吗?
Update:
rd2=rd.map(lambda x: (x[1], x[0][0] , x[0][1]))
我的 RDD 格式为:
[(0, 'abc', '1,2'), (1, 'def', '4,6,7')]
转换为数据框:
rd2.toDF(["Index", "Name" , "Number"])
它仍然给我错误:
An error occurred while calling o2271.showString.
: java.lang.IllegalStateException: SparkContext has been shutdown
at org.apache.spark.SparkContext.runJob(SparkContext.scala:2021)
at org.apache.spark.SparkContext.runJob(SparkContext.scala:2050)