cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to change line separator for csv file exported from dataframe in databricks

tunguyen90
New Contributor

Hello,

Currently, I'm facing problem with line separator inside csv file, which is exported from data frame in Azure Databricks (version Spark 2.4.3) to Azure Blob storage. All those csv files contains LF as line-separator. I need to have CRLF (\r\n) as line separator in those csv files. Although I've tried different ways to change that default line separator into my target line separator, it doesn't work. Up to now, I tried following ways

1. In databricks notebook, I added option to customize line separator as following.

df.write.format("com.databricks.spark.csv").option("header","true").option("lineSep",'\r\n').mode("overwrite").save(target_folder);

Looks like such option("lineSep") doesn't work yet, at least in my version Spark 2.4.3. I checked in other similar question, in forum they said that this doesn't work as well in Spark 2.4.4.

2. In databricks notebook, I tried to add following line

spark._jvm.java.lang.System.setProperty("line.separator", "\r\n");

Looks like that such setProperty didn't change also the default line separator once parsing and writing data to output in csv files in Azure blob storage.

Maybe someone has other suggestion / solution for this problem ? Thanks a lot for your help.

3 REPLIES 3

shyam_9
Databricks Employee
Databricks Employee

Hi @tunguyen90,

Please go through the below answer,

https://forums.databricks.com/questions/12831/custom-line-separator.html

neilbest-db
New Contributor II

The linked answer seems to be about reading. @tunguyen90 asked about writing. Aren't they distinct issues? I am also looking for latest info on the writer.

Nikhila
New Contributor II

Hi,

Have you got the solution for above problem.Kindly let me know.

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group