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.

Sociopath
  • 13,068
  • 19
  • 47
  • 75
Bhaskar
  • 51
  • 2
  • 6

1 Answers1

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|
+-----+-------+
Manoj Kumar Dhakad
  • 1,862
  • 1
  • 12
  • 26