spark dataframe存储到本地csv或者txt,会基于hahoop存储为一个文件夹如a.csv文件夹。
为了存储为单一文件的方式如下:
1.
df.coalesce(1).write.csv('result.csv')
coalesce(num),Returns a new DataFrame
that has exactly numPartitions partitions.作为一个整体返回。
2.toPandas()
变为pandas的dataframe来存储,用to_csv等接口,确定,要保证内存够用,后者一些琐碎文件可以用mode=‘a'追加的方式,不断循环存储为一个csv到本地。