INNER CODE UNIT · Python
impute_NA_with_end_of_distribution
ashishpatel26/Amazing-Feature-Engineering · feature_cleaning/missing_data.py:91
def impute_NA_with_end_of_distribution(data,NA_col=[]):
"""
replacing the NA by values that are at the far end of the distribution of that variable
calculated by mean + 3*std
"""
data_copy = data.copy(deep=True)
for i in NA_col:
if data_copy[i].isnull().sum()>0:
data_copy[i+'_impute_end_of_distri'] = data_copy[i].fillna(data[i].mean()+3*data[i].std())
else:
warn("Column %s has no missing" % i)
return data_copy
def impute_NA_with_random(data,NA_col=[],random_state=0):
"""
replacing the NA with random sampling from the pool of available observations of the variable