如何在 ipython 中将 Spark RDD 转换为 Pandas 数据帧? [英] How to convert Spark RDD to pandas dataframe in ipython?

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

问题描述

我有一个 RDD,我想将它转换为 pandas dataframe.我知道将 RDD 转换为普通的 dataframe 我们可以做

df = rdd1.toDF()

但我想将 RDD 转换为 pandas dataframe 而不是普通的 dataframe.我该怎么做?

解决方案

您可以使用函数 toPandas():

<块引用>

将此 DataFrame 的内容作为 Pandas pandas.DataFrame 返回.

仅当 Pandas 已安装且可用时才可用.

<预><代码>>>>df.toPandas()年龄名称0 2 爱丽丝1 5 鲍勃

I have a RDD and I want to convert it to pandas dataframe. I know that to convert and RDD to a normal dataframe we can do

df = rdd1.toDF()

But I want to convert the RDD to pandas dataframe and not a normal dataframe. How can I do it?

解决方案

You can use function toPandas():

Returns the contents of this DataFrame as Pandas pandas.DataFrame.

This is only available if Pandas is installed and available.

>>> df.toPandas()  
   age   name
0    2  Alice
1    5    Bob

这篇关于如何在 ipython 中将 Spark RDD 转换为 Pandas 数据帧?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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