如何数据框导出为CSV斯卡拉?
问题描述:
我如何使用Scala星火的数据框导出为CSV文件?
How can I export Spark's DataFrame to csv file using Scala?
答
最简单,要做到这一点最好的办法就是使用的 火花CSV
库。您可以在提供的链接和 此处$ C查看文档$ C>
是如何加载和/数据保存到数据帧中阶例子。
Easiest and best way to do this is to use spark-csv
library. You can check the documentation in the provided link and here
is the scala example of how to load and save data from/to DataFrame.
code(星火1.4 +):
dataFrame.write.format("com.databricks.spark.csv").save("myFile.csv")
编辑:
星火创建部分文件,同时节省CSV数据,如果你想将部分文件合并成一个单一的CSV,请参考以下内容:
Spark creates part-files while saving the csv data, if you want to merge the part-files into a single csv, please refer the following: