How do I replace nulls with 0's in a Dataset

i want to replace nulls with 0 in df, what transformation and action need to be performed

Hi Krishnakanth,

Could you provide a bit of more example code?
It would help us solving it.

for numeric columns containing nulls

df.na.fill(0)

this will replace nulls with 0’s for all the numeric dataType columns

for specific column
df.na.fill(0, Array(“column_name”))

df.na.fill(“missing data”)

this will replace nulls with “missing data” for all the stringdataType columns

for specific column
df.na.fill(“missing data”, Array(“column_name”))

hope this helps

-deepak

1 Like