我正在尝试将pyspark中的pipelinedRDD转换为数据帧。这是代码片段:
newRDD = rdd.map(lambda row: Row(row.__fields__ + ["tag"])(row + (tagScripts(row), )))
df = newRDD.toDF()
但是,当我运行代码时,收到以下错误:
'list' object has no attribute 'encode'
我尝试了多种其他组合,例如使用以下方法将其转换为Pandas数据帧:
newRDD = rdd.map(lambda row: Row(row.__fields__ + ["tag"])(row + (tagScripts(row), )))
df = newRDD.toPandas()
但最后我收到了这个错误:
AttributeError: 'PipelinedRDD' object has no attribute 'toPandas'
任何帮助都将不胜感激。谢谢你抽出时间。
rdd.toDF()
或rdd.toPandas()
仅用于SparkSession
。若要修复代码,请尝试以下操作:
相关问题 更多 >
编程相关推荐