def normalize ( df , style = 'mean' ) : if style == 'mean' : df_mean , df_std = df . mean ( ) , df . std ( ) return ( df - df_mean ) / df_std elif style == 'minmax' : col_min , col_max = df . min ( ) , df . max ( ) return ( df - col_min ) / ( col_max - col_min ) else : return style ( df )
normalize data from datafram python
Returns a normalized version of a DataFrame or Series Parameters : df - DataFrame or Series The data to normalize style - function or string default mean The style to use when computing the norms . Takes mean or minmax to do mean or min - max normalization respectively . User - defined functions that take a pandas Series as input and return a normalized pandas Series are also accepted
def normalize(df, style = 'mean'):
    """ Returns a normalized version of a DataFrame or Series
    Parameters:
    df - DataFrame or Series
        The data to normalize
    style - function or string, default 'mean'
        The style to use when computing the norms. Takes 'mean' or 'minmax' to
        do mean or min-max normalization respectively. User-defined functions that take
        a pandas Series as input and return a normalized pandas Series are also accepted
    """
    if style == 'mean':
        df_mean,df_std = df.mean(),df.std()
        return (df-df_mean)/df_std
    elif style == 'minmax':
        col_min,col_max = df.min(),df.max()
        return (df-col_min)/(col_max-col_min)
    else:
        return style(df)