merge_machine/exact_linker.py
def create_new_column(tab, cols, sep=' '):
    """Merges columns in list cols to """
    
    if isinstance(cols, str):
        cols = [cols]
        
    if len(cols) == 0:
        raise Exception('Missing value in column pairs')
    else:    
        # Create new_column name
        new_col_name = '_pre_processed_' + '__'.join(cols)
        while new_col_name in tab.columns:
            new_col_name += '__new'
        tab.loc[:, new_col_name] = tab.loc[:, cols[0]].fillna('')
        for col in cols[1:]:
            tab.loc[:, new_col_name] += sep + tab.loc[:, col].fillna('')
        tab.loc[:, new_col_name] = tab.loc[:, new_col_name].str.strip(sep)
        sel = tab.loc[:, new_col_name] == ''
        tab.loc[sel, new_col_name] = np.nan
    
        # Pre-process column
        sel = tab[new_col_name].notnull()
        print('Pre-processing ', new_col_name)
        tab.loc[sel, new_col_name] = pd_pre_process(tab.loc[sel, new_col_name], 
                                                       remove_punctuation=True)
        return tab, new_col_name
Merges columns in list cols to 
Merges columns in list cols to
Merges columns in list cols to
def create_new_column(tab, cols, sep=' '):
    if isinstance(cols, str):
        cols = [cols]
    if len(cols) == 0:
        raise Exception('Missing value in column pairs')
    else:    
        new_col_name = '_pre_processed_' + '__'.join(cols)
        while new_col_name in tab.columns:
            new_col_name += '__new'
        tab.loc[:, new_col_name] = tab.loc[:, cols[0]].fillna('')
        for col in cols[1:]:
            tab.loc[:, new_col_name] += sep + tab.loc[:, col].fillna('')
        tab.loc[:, new_col_name] = tab.loc[:, new_col_name].str.strip(sep)
        sel = tab.loc[:, new_col_name] == ''
        tab.loc[sel, new_col_name] = np.nan
        sel = tab[new_col_name].notnull()
        print('Pre-processing ', new_col_name)
        tab.loc[sel, new_col_name] = pd_pre_process(tab.loc[sel, new_col_name], 
                                                       remove_punctuation=True)
        return tab, new_col_name
def create_new_column ( tab , cols , sep = ' ' ) : if isinstance ( cols , str ) : cols = [ cols ] if len ( cols ) == 0 : raise Exception ( 'Missing value in column pairs' ) else : new_col_name = '_pre_processed_' + '__' . join ( cols ) while new_col_name in tab . columns : new_col_name += '__new' tab . loc [ : , new_col_name ] = tab . loc [ : , cols [ 0 ] ] . fillna ( '' ) for col in cols [ 1 : ] : tab . loc [ : , new_col_name ] += sep + tab . loc [ : , col ] . fillna ( '' ) tab . loc [ : , new_col_name ] = tab . loc [ : , new_col_name ] . str . strip ( sep ) sel = tab . loc [ : , new_col_name ] == '' tab . loc [ sel , new_col_name ] = np . nan sel = tab [ new_col_name ] . notnull ( ) print ( 'Pre-processing ' , new_col_name ) tab . loc [ sel , new_col_name ] = pd_pre_process ( tab . loc [ sel , new_col_name ] , remove_punctuation = True ) return tab , new_col_name
Merges columns in list cols to
Merges columns in list cols to
"""Merges columns in list cols to """ # Create new_column name # Pre-process column
tab
cols
sep