cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
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
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
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.

ShriS1221
New Contributor II

Yeah , thank you .โ€‹

AmanSehgal
Honored Contributor III

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

Kaniz
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)

Kaniz
Community Manager
Community Manager

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

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.