INNER CODE UNIT · Python
impute_NA_with_arbitrary
ashishpatel26/Amazing-Feature-Engineering · feature_cleaning/missing_data.py:57
def impute_NA_with_arbitrary(data,impute_value,NA_col=[]):
"""
replacing NA with arbitrary values.
"""
data_copy = data.copy(deep=True)
for i in NA_col:
if data_copy[i].isnull().sum()>0:
data_copy[i+'_'+str(impute_value)] = data_copy[i].fillna(impute_value)
else:
warn("Column %s has no missing cases" % i)
return data_copy
def impute_NA_with_avg(data,strategy='mean',NA_col=[]):
"""
replacing the NA with mean/median/most frequent values of that variable.
Note it should only be performed over training set and then propagated to test set.