feature-engineering-and-data-transformations/using-toy-exmaples/feature_cleaning/missing_data.py
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
    """
    
    data_copy = data.copy(deep=True)
    for i in NA_col:
        if data_copy[i].isnull().sum()>0:
            data_copy[i+'_random'] = data_copy[i]
            # extract the random sample to fill the na
            random_sample = data_copy[i].dropna().sample(data_copy[i].isnull().sum(), random_state=random_state)
            random_sample.index = data_copy[data_copy[i].isnull()].index
            data_copy.loc[data_copy[i].isnull(), str(i)+'_random'] = random_sample
        else:
            warn("Column %s has no missing" % i)
    return data_copy

    replacing the NA with random sampling from the pool of available observations of the variable
    
replacing the NA with random sampling from the pool of available observations of the variable
replacing the NA with random sampling from the pool of available observations of the variable
def impute_NA_with_random(data,NA_col=[],random_state=0):
    data_copy = data.copy(deep=True)
    for i in NA_col:
        if data_copy[i].isnull().sum()>0:
            data_copy[i+'_random'] = data_copy[i]
            random_sample = data_copy[i].dropna().sample(data_copy[i].isnull().sum(), random_state=random_state)
            random_sample.index = data_copy[data_copy[i].isnull()].index
            data_copy.loc[data_copy[i].isnull(), str(i)+'_random'] = random_sample
        else:
            warn("Column %s has no missing" % i)
    return data_copy
def impute_NA_with_random ( data , NA_col = [ ] , random_state = 0 ) : data_copy = data . copy ( deep = True ) for i in NA_col : if data_copy [ i ] . isnull ( ) . sum ( ) > 0 : data_copy [ i + '_random' ] = data_copy [ i ] random_sample = data_copy [ i ] . dropna ( ) . sample ( data_copy [ i ] . isnull ( ) . sum ( ) , random_state = random_state ) random_sample . index = data_copy [ data_copy [ i ] . isnull ( ) ] . index data_copy . loc [ data_copy [ i ] . isnull ( ) , str ( i ) + '_random' ] = random_sample else : warn ( "Column %s has no missing" % i ) return data_copy
replacing the NA with random sampling from the pool of available observations of the variable
replacing the NA with random sampling from the pool of available observations of the variable
"""
    replacing the NA with random sampling from the pool of available observations of the variable
    """ # extract the random sample to fill the na
data
NA_col
random_state