如何将pyspark数据帧写入HDFS,然后如何将其读回数据帧? [英] How to write pyspark dataframe to HDFS and then how to read it back into dataframe?
本文介绍了如何将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.
-
从HDFS(Spark 1.6)读取DataFrame.
reading DataFrame from HDFS (Spark 1.6).
一些格式选项包括
csv
,parquet
,json
等.some of the format options are
csv
,parquet
,json
etc.from pyspark.sql import SQLContext sqlContext = SQLContext(sc) sqlContext.read.format('parquet').load('/path/to/file')
format方法采用诸如parquet
,csv
,json
等的参数.
the format method takes argument such as parquet
, csv
, json
etc.
这篇关于如何将pyspark数据帧写入HDFS,然后如何将其读回数据帧?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文