INNER CODE UNIT · Python

add_var_denote_NA

ashishpatel26/Amazing-Feature-Engineering · feature_cleaning/missing_data.py:41

def add_var_denote_NA(data,NA_col=[]):
    """
    creating an additional variable indicating whether the data 
    was missing for that observation (1) or not (0).
    """
  
    data_copy = data.copy(deep=True)
    for i in NA_col:
        if data_copy[i].isnull().sum()>0:
            data_copy[i+'_is_NA'] = np.where(data_copy[i].isnull(),1,0)
        else:
            warn("Column %s has no missing cases" % i)
            
    return data_copy


def impute_NA_with_arbitrary(data,impute_value,NA_col=[]):
    """

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…