I Have one data set which contains some categorical variables and they have some missing(NA/Null). I Want to fill these NA/Nulls with Mode of that Column. I tired Following thing but This didn't work
MD=Data['Gender'].mode()
Data['Gender'].fillna(value=MD,inplace=True)
MD=Data['Married'].mode()
Data['Married'].fillna(value=MD,inplace=True)
MD=Data['Dependents'].mode()
Data['Dependents'].fillna(value=MD,inplace=True)
MD=Data['Self_Employed'].mode()
Data['Self_Employed'].fillna(value=MD,inplace=True)
MD=Data['Credit_History'].mode()
Data['Credit_History'].fillna(value=MD,inplace=True)
Gender 26
Married 6
Dependents 30
Education 0
Self_Employed 64
ApplicantIncome 0
CoapplicantIncome 0
LoanAmount 0
Loan_Amount_Term 0
Credit_History 100
Property_Area 0
Loan_Status 0
Still its Showing missing values.
Try this:
Data['Married'].fillna(Data['Married'].mode(), inplace=True)
Or Try this:
Data['Married'].fillna(Data['Married'].value_counts().index[0], inplace=True)
Ensure that dtype of your categorical variables is object or category.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With