2

How to replace empty string with \N in spark dataframe.

I tried the below one:

Df.na.replace(Seq("column1"),Map("" -> null)).na.fill("\N", Seq("column1"))

It's throwing me an error.

0

1 Answer 1

5

You have to do like below

//Input df

+-----+-------+
| name|address|
+-----+-------+
|Manoj|Chennai|
|     |  Delhi|
|Alice|       |
+-----+-------+

//Replacement logic

df.na.replace(Seq("name","address"),Map(""->"\\n")).show

//Output df
+-----+-------+
| name|address|
+-----+-------+
|Manoj|Chennai|
|   \n|  Delhi|
|Alice|     \n|
+-----+-------+
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.