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:ย 

Removing new line character from spark dataframe column

ShriS1221
New Contributor II

I have to remove new line character from entire column of a dataframe , I tried with regex_replace but its not working.

Help me on this.โ€‹

1 ACCEPTED SOLUTION

Accepted Solutions

Kaniz_Fatma
Community Manager
Community Manager

Hi @Shriram Sโ€‹ ,

Please try the following code:

import pandas as pd
 
df=pd.read_csv("xyz.csv")
 
col = ["columns_of _the _dataframes_that_needs_modification"]
 
new_df = df[col].replace('\\n',' ', regex=True)
 
new_df.to_csv("newFile.csv", index=False)

View solution in original post

5 REPLIES 5

Kaniz_Fatma
Community Manager
Community Manager

Hi @Shriram Sโ€‹ ! My name is Kaniz, and I'm the technical moderator here. Great to meet you, and thanks for your question! Let's see if your peers in the community have an answer to your question first. Or else I will get back to you soon. Thanks.

Yeah , thank you .โ€‹

AmanSehgal
Honored Contributor III

Could you please provide example of your data and the code you've tried?

Kaniz_Fatma
Community Manager
Community Manager

Hi @Shriram Sโ€‹ ,

Please try the following code:

import pandas as pd
 
df=pd.read_csv("xyz.csv")
 
col = ["columns_of _the _dataframes_that_needs_modification"]
 
new_df = df[col].replace('\\n',' ', regex=True)
 
new_df.to_csv("newFile.csv", index=False)

Hi @Shriram Sโ€‹ , Did the above provided code work for you?

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