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.
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.
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|
+-----+-------+