def table_apply(table, func, subset=None):
from . import Table<EOL>df = table.to_df()<EOL>if subset is not None:<EOL><INDENT>subset = np.atleast_1d(subset)<EOL>if any([i not in df.columns for i in subset]):<EOL><INDENT>err = np.where([i not in df.columns for i in subset])[<NUM_LIT:0>]<EOL>err = "<STR_LIT>".format(<EOL>[subset[i] for i in err])<EOL>raise ValueError(err)<EOL><DEDENT>for col in subset:<EOL><INDENT>df[col] = df[col].apply(func)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>df = df.apply(func)<EOL><DEDENT>if isinstance(df, pd.Series):<EOL><INDENT>df = pd.DataFrame(df).T<EOL><DEDENT>tab = Table.from_df(df)<EOL>return tab<EOL>
Applies a function to each column and returns a Table.

    Uses pandas `apply` under the hood, then converts back to a Table

    Args:
        table : instance of Table
            The table to apply your function to
        func : function
            Any function that will work with DataFrame.apply
        subset : list | None
            A list of columns to apply the function to. If None, function
            will be applied to all columns in table

    Returns
    -------
    tab : instance of Table
        A table with the given function applied. It will either be the
        shape == shape(table), or shape (1, table.shape[1])