Skip to content

Instantly share code, notes, and snippets.

@srishtis
Created October 9, 2018 11:25
Show Gist options
  • Save srishtis/43f129f7ce2cec2a232a18cd414e667c to your computer and use it in GitHub Desktop.
Save srishtis/43f129f7ce2cec2a232a18cd414e667c to your computer and use it in GitHub Desktop.
Imputing missing values part 1
# columns with attributes like Pool, Fence etc. marked as NaN indicate the absence of these features.
attributes_with_na = ['PoolQC','MiscFeature','Alley','Fence','MasVnrType','FireplaceQu',
'GarageQual','GarageCond','GarageFinish','GarageType',
'BsmtExposure','BsmtCond','BsmtQual','BsmtFinType1','BsmtFinType2']
# replace 'NaN' with 'None' in these columns
for col in attributes_with_na:
total_df[col].fillna('None',inplace=True)
#NAs in basement related columns will indicate no masonry veneer. Thus replacing MasVnr Area with 0
total_df.MasVnrArea.fillna(0,inplace=True)
#NAs in basement related columns will indicate no basement. Thus replacing all areas and count column with 0
total_df.BsmtFullBath.fillna(0,inplace=True)
total_df.BsmtHalfBath.fillna(0,inplace=True)
total_df.BsmtFinSF1.fillna(0,inplace=True)
total_df.BsmtFinSF2.fillna(0,inplace=True)
total_df.BsmtUnfSF.fillna(0,inplace=True)
total_df.TotalBsmtSF.fillna(0,inplace=True)
#Similarly for Garage Cars-- fill with 0; cause if no garage, no cars can parked in it
total_df.GarageCars.fillna(0,inplace=True)
# doing the same for GarageArea
total_df.GarageArea.fillna(0,inplace=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment