def captureStandardization(df, columns=None):
    """A function factory that creates a function for standardizing all columns
    in df with each columns mean and standard deviation."""
    if columns is None:
        columns = df.columns
    stdParams = {}
    for c in columns:
        mu = df[c].mean()
        sigma2 = df[c].std()
        stdParams[c] = (mu, sigma2)
    
    def stdFunc(df):
        df = df.copy()
        for c in columns:
            df.loc[:, c] = (df[c] - stdParams[c][0]) / stdParams[c][1]
        return df
    return stdFunc