如何RDD对象转换为数据帧中的火花 [英] How to convert rdd object to dataframe in spark
问题描述
我怎么能转换成一个RDD( org.apache.spark.rdd.RDD [org.apache.spark.sql.Row]
)到数据框 org.apache.spark.sql.DataFrame
。我转换一个数据帧使用 .rdd
来RDD。处理完后我想回去的数据帧。我怎样才能做到这一点?
<一个href=\"https://spark.apache.org/docs/latest/api/scala/index.html#org.apache.spark.sql.SQLContext\"><$c$c>SqlContext$c$c>拥有一批 createDataFrame
的创建方法数据帧
给予 RDD
。我想这些人会为你的环境中工作。
例如:
高清createDataFrame(rowRDD:RDD [行]模式:StructType):数据帧
使用给定的含行的RDD创建一个数据框
架构。
块引用>How can I convert an RDD (
org.apache.spark.rdd.RDD[org.apache.spark.sql.Row]
) to a Dataframeorg.apache.spark.sql.DataFrame
. I converted a dataframe to rdd using.rdd
. After processing it I want it back in dataframe. How can I do this ?解决方案
SqlContext
has a number ofcreateDataFrame
methods that create aDataFrame
given anRDD
. I imagine one of these will work for your context.For example:
def createDataFrame(rowRDD: RDD[Row], schema: StructType): DataFrame
Creates a DataFrame from an RDD containing Rows using the given schema.
这篇关于如何RDD对象转换为数据帧中的火花的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!