如何RDD对象转换为数据帧中的火花 [英] How to convert rdd object to dataframe in spark

查看:175
本文介绍了如何RDD对象转换为数据帧中的火花的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能转换成一个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拥有一批 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 Dataframe org.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 of createDataFrame methods that create a DataFrame given an RDD. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆