src/syndp/utils/preprocessing.py
def undummify(data :pd.DataFrame, columns :list, prefix_separator="-"):
    '''
    This function changes tabular data's categorical variable's one-hot dummy encoding to the original form
    data : original tabular data
    columns : a list of names of categorical values
    prefix_sep : prefix separator. Mostly is "-"
    '''
    # cols2collapse = {
    #     item.split(prefix_separator)[0]: (prefix_separator in item) for item in data.columns
    # }
    
    continuous_list = [cont for cont in data.columns if cont.split(prefix_separator)[0] not in columns]
    data1 = data[continuous_list].copy() # data to concat later

    undummified_list  = []
    for col in columns:
        undummified = data.filter(like=col).idxmax(axis=1).apply(lambda x : x.split(prefix_separator, maxsplit=1)[1]).rename(col)
        undummified_list.append(undummified) 
    
    recovered_data = pd.concat([data1, *undummified_list], axis=1)
    return recovered_data

    This function changes tabular data's categorical variable's one-hot dummy encoding to the original form
    data : original tabular data
    columns : a list of names of categorical values
    prefix_sep : prefix separator. Mostly is "-"
    
This function changes tabular data's categorical variable's one-hot dummy encoding to the original form
data : original tabular data
columns : a list of names of categorical values
prefix_sep : prefix separator. Mostly is "-"
This function changes tabular data ' s categorical variable ' s one - hot dummy encoding to the original form data : original tabular data columns : a list of names of categorical values prefix_sep : prefix separator . Mostly is " - "
def undummify(data :pd.DataFrame, columns :list, prefix_separator="-"):
    continuous_list = [cont for cont in data.columns if cont.split(prefix_separator)[0] not in columns]
    data1 = data[continuous_list].copy() 
    undummified_list  = []
    for col in columns:
        undummified = data.filter(like=col).idxmax(axis=1).apply(lambda x : x.split(prefix_separator, maxsplit=1)[1]).rename(col)
        undummified_list.append(undummified) 
    recovered_data = pd.concat([data1, *undummified_list], axis=1)
    return recovered_data
def undummify ( data : pd . DataFrame , columns : list , prefix_separator = "-" ) : continuous_list = [ cont for cont in data . columns if cont . split ( prefix_separator ) [ 0 ] not in columns ] data1 = data [ continuous_list ] . copy ( ) undummified_list = [ ] for col in columns : undummified = data . filter ( like = col ) . idxmax ( axis = 1 ) . apply ( lambda x : x . split ( prefix_separator , maxsplit = 1 ) [ 1 ] ) . rename ( col ) undummified_list . append ( undummified ) recovered_data = pd . concat ( [ data1 , * undummified_list ] , axis = 1 ) return recovered_data
This function changes tabular data's categorical variable's one-hot dummy encoding to the original form
data : original tabular data
columns : a list of names of categorical values
prefix_sep : prefix separator.
This function changes tabular data ' s categorical variable ' s one - hot dummy encoding to the original form data : original tabular data columns : a list of names of categorical values prefix_sep : prefix separator .
'''
    This function changes tabular data's categorical variable's one-hot dummy encoding to the original form
    data : original tabular data
    columns : a list of names of categorical values
    prefix_sep : prefix separator. Mostly is "-"
    ''' # cols2collapse = { #     item.split(prefix_separator)[0]: (prefix_separator in item) for item in data.columns # } # data to concat later
data
pd.DataFrame
columns
list
prefix_separator