我有一个包含多列的rdd,想要提取一个名为"age"的列。我试过了:
rddAge = df.rdd.map(lambda row: Row(age=row.age))
代码不返回任何错误。但是当我简单地尝试做一个rddAge.count((时,我得到了一个很长的回溯:
Py4JJavaError: An error occurred while calling z:org.apache.spark.api.python.PythonRDD.collectAndServe.
: org.apache.spark.SparkException: Job aborted due to stage failure: Task 0 in stage 29.0 failed 10 times, most recent failure: Lost task 0.9 in stage 29.0 (TID 365, yp-spark-dal09-env5-0048): org.apache.spark.api.python.PythonException: Traceback (most recent call last): ...
我做错了吗?
谢谢
您要导入 Row?导入行对我来说工作正常
from pyspark.sql import Row
rddAge = df.rdd.map(lambda row: Row(age=row.rddAge))
rddAge.count()
在 Spark 2
中,可以直接select
数据帧顶部的列,scala
中对应的代码片段为:
val ageDF = df.select("age")
ageDF.printSchema()
输出:
root
|-- age: long (nullable = true)
希望这有帮助...