Skip to content

Instantly share code, notes, and snippets.

@terrah27
Created March 12, 2022 01:51
Show Gist options
  • Save terrah27/d3e209aff0453db2447fea359caf1738 to your computer and use it in GitHub Desktop.
Save terrah27/d3e209aff0453db2447fea359caf1738 to your computer and use it in GitHub Desktop.
# check number of missing values
print(f"Missing Values Before Flagging: {df['OCCUPATION_TYPE'].isnull().sum()}")
# check values of OCCUPATION_TYPE feature
print(df['OCCUPATION_TYPE'].value_counts())
# replace values with flag 1=data present 0=data missing
df['OCCUPATION_TYPE'] = np.where(df['OCCUPATION_TYPE'].isnull(), # condition
1, # value if true
0 # value if false
)
# check number of missing values
print(f"Missing Values After Flagging: {df['OCCUPATION_TYPE'].isnull().sum()}")
# check values of OCCUPATION_TYPE feature
df['OCCUPATION_TYPE'].value_counts()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment