def transform_cols_from_library(df, scaler_library, inverse=False, columns=[]):
    """Accepts a df and a scaler_library that was transformed using make_scaler_library.
    Inverse tansforms listed columns (if columns =[] then all columns)
    Returns a dataframe with all columns of original df."""
    df_out = df.copy()
    if len(columns) == 0:
        columns = df.columns
    for col in columns:
        scaler = scaler_library[col]
        if hasattr(scaler, 'data_range_') == False:
            raise Exception(f'The scaler for {col} is not fitted.')
        if inverse == False:
            scaled_col = scaler.transform(df[col].values.reshape(-1, 1))
        elif inverse == True:
            scaled_col = scaler.inverse_transform(df[col].values.reshape(-1, 1)
                )
        df_out[col] = scaled_col.ravel()
    return df_out
