Skip to content

Instantly share code, notes, and snippets.

@terrah27
Created March 12, 2022 01:35
Show Gist options
  • Save terrah27/0eb7003345be2e0f9506723383c52e5e to your computer and use it in GitHub Desktop.
Save terrah27/0eb7003345be2e0f9506723383c52e5e to your computer and use it in GitHub Desktop.
# impute using fillna
# make a copy of dataframe for example purposes
imputed_df = df_threshold.copy()
# list of columns to impute
impute_cols = ['AMT_REQ_CREDIT_BUREAU_YEAR',
'AMT_REQ_CREDIT_BUREAU_HOUR',
'AMT_REQ_CREDIT_BUREAU_DAY',
'AMT_REQ_CREDIT_BUREAU_WEEK',
'AMT_REQ_CREDIT_BUREAU_MON',
'AMT_REQ_CREDIT_BUREAU_QRT']
# fill missing values with mean
for col in impute_cols:
imputed_df[col] = imputed_df[col].fillna(imputed_df[col].mean())
# get updated missing value info
get_missing_values_info(imputed_df).head(20)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment