Skip to content

Instantly share code, notes, and snippets.

@aniruddha27
Last active March 16, 2020 09:54
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 aniruddha27/a94552e948282df673b81569a067a0c8 to your computer and use it in GitHub Desktop.
Save aniruddha27/a94552e948282df673b81569a067a0c8 to your computer and use it in GitHub Desktop.
# Ordinal features
#NA means no Pool
train['PoolQC'].replace(['Ex','Gd','TA','Fa',np.nan],[4,3,2,1,0],inplace=True)
# NA means no fence
train['Fence'].replace(['GdPrv','MnPrv','GdWo','MnWw',np.nan],[4,3,2,1,0],inplace=True)
# NA means no fireplace
train['FireplaceQu'].replace(['Ex','Gd','TA','Fa','Po',np.nan],[5,4,3,2,1,0],inplace=True)
# Nominal features
# NA means no miscellaneous feature
train['MiscFeature'].fillna('None',inplace=True)
# NA means no alley access
train['Alley'].fillna('None',inplace=True)
# Numerical features
# Replace null lotfrontage with average of the neighborhood
train['LotFrontage'] = train.groupby('Neighborhood')['LotFrontage'].transform(lambda x:x.fillna(x.median()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment