Unable to fill missing value



I just started working on this problem. I am trying to impute missing value for “Married” column. As this has only 3 missing values I tried to impute them as “No”. I used below code to impute but it is not working. Tried with different options but I am not getting any error but the missing value is still there.

loan_dat$Married[which(is.na(loan_dat$Married))] <- "No"
loan_dat$Married <- ifelse(is.na(loan_dat$Married), "No", loan_dat$Married)

Married column is categorical and not factor in my dataframe.
Any help please.



Try as follow:
loan_dat$Married[is.na(loan_dat$Married)] <- "No"

I hope it works.


No this also didn’t work.


can you please show some line of data where NA comes so I will try on my system and let you know?


Please check above lines.


Ok I will try and let you know


Hi @yaswanth912,

Try the following code:

loan_dat$Married[loan_dat$Married == ""] = "No"

Let us know if it works.


Hey @pjoshi15, this worked. Wondering what was the difference between my code and the one you provided?
But I have changed the inverted commas from the one provided by you.

loan_dat$Married[loan_dat$Married == ""] <- "No" (this worked)


Ok There is no ‘NA’ it was white space thatsy


Exactly :slight_smile:


I have used Pandas and used the following code for Data Munging.

data.Self_Employed = data.Self_Employed.fillna('No') and it works