java Spark:如何使用标题保存数据帧?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36505156/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Spark: How to save a dataframe with headers?
提问by user3897533
dataframe.saveasTextFile
, saves only the data in a delimited format. How do I save the dataframe with headers in JAVA.
dataframe.saveasTextFile
, 仅以分隔格式保存数据。如何在 JAVA 中保存带有标题的数据帧。
sourceRufFrame.toJavaRDD().map(new TildaDelimiter()).coalesce(1, true).saveAsTextFile(targetSrcFilePath);
回答by Srini
If you want to save as csv file, i would suggest using spark-csv
package. You can save your dataframe simply with spark-csv
as below with header.
如果你想保存为 csv 文件,我建议使用spark-csv
package.json 。您可以spark-csv
使用标题简单地保存您的数据框,如下所示。
dataFrame.write
.format("com.databricks.spark.csv")
.option("header", "true")
.option("delimiter",<your delimiter>)
.save(output)
You can refer below link, for further information: https://github.com/databricks/spark-csv
您可以参考以下链接,了解更多信息:https: //github.com/databricks/spark-csv
Spark-csv
has maven dependency.
Spark-csv
有 maven 依赖。
回答by Chitral Verma
With Spark 2.x,
使用 Spark 2.x,
df.write.option("header", "true").csv("path")
Cheers
干杯