如何将pyspark数据帧写入HDFS,然后如何将其读回数据帧? [英] How to write pyspark dataframe to HDFS and then how to read it back into dataframe?

查看:33
本文介绍了如何将pyspark数据帧写入HDFS,然后如何将其读回数据帧?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常大的 pyspark 数据框.所以我想对它的子集进行预处理,然后将它们存储到 hdfs.后来我想阅读所有这些并合并在一起.谢谢.

I have a very big pyspark dataframe. So I want to perform pre processing on subsets of it and then store them to hdfs. Later I want to read all of them and merge together. Thanks.

推荐答案

  • 将 DataFrame 写入 HDFS (Spark 1.6).

    • writing DataFrame to HDFS (Spark 1.6).

      df.write.save('/target/path/', format='parquet', mode='append') ## df is an existing DataFrame object.
      

    • 一些格式选项是csvparquetjson

      some of the format options are csv, parquet, json etc.

      • 从 HDFS (Spark 1.6) 读取数据帧.

      • reading DataFrame from HDFS (Spark 1.6).

      from pyspark.sql import SQLContext
      sqlContext = SQLContext(sc)
      sqlContext.read.format('parquet').load('/path/to/file') 
      

      format 方法接受parquetcsvjson 等参数

      the format method takes argument such as parquet, csv, json etc.

      这篇关于如何将pyspark数据帧写入HDFS,然后如何将其读回数据帧?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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