How can I save records of a DataFrame
into a tab delimited output file?
The DataFame
looks like below:
>>> csvDf.show(2,False)
1. |1 |Eldon Base for stackable storage shelf, platinum |Muhammed
MacIntyre|3 |-213.25|38.94 |35 |Nunavut|Storage & Organization
|0.8 |
2. |2 |1.7 Cubic Foot Compact "Cube" Office Refrigerators|Barry
French |293|457.81 |208.16|68.02|Nunavut|Appliances
|0.58|
Just pass delimiter
option to the writer:
csvDf.write.option("delimiter", "\t").csv(output_path)
In Spark 1.6 use spark-csv
package (check README
for detailed instructions) with the same option:
csvDf.write.option("delimiter", "\t").format("com.databricks.spark.csv").save(output_path)
In Spark 2.4.3 it is:
csvDf
.write
.option("sep", "\t")
.option("encoding", "UTF-8")
.csv(targetFilePath)
this worked for me ...
csvDf.rdd.map(lambda x: '\t'.join(x)).coalesce(1).saveAsTextFile('/output/csv/6.csv')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With