Skip to content

Instantly share code, notes, and snippets.

@HeenaR17
Created April 3, 2021 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HeenaR17/39ebc838195d453dd77ea4c49508ac19 to your computer and use it in GitHub Desktop.
Save HeenaR17/39ebc838195d453dd77ea4c49508ac19 to your computer and use it in GitHub Desktop.
# Replacing missing values in Glucose column with median of respective class.
def impute_Glucose(cols):
Glucose=cols[0]
Outcome=cols[1]
if pd.isnull(Glucose):
if Outcome == 0:
return 120
else:
return 142
else:
return Glucose
df_copy['Glucose']=df_copy[['Glucose','Outcome']].apply(impute_Glucose, axis=1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment