<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def categorical_to_numeric(table):
 """Encode categorical columns to numeric by converting each category to an integer value. Parameters table : pandas.DataFrame Table with categorical columns to encode. Returns ------- encoded : pandas.DataFrame Table with categorical columns encoded as numeric. Numeric columns in the input table remain unchanged. """

    def transform(column):
        if is_categorical_dtype(column.dtype):
            return column.cat.codes
        if column.dtype.char == "O":
            try:
                nc = column.astype(numpy.int64)
            except ValueError:
                classes = column.dropna().unique()
                classes.sort(kind="mergesort")
                nc = column.replace(classes, numpy.arange(classes.shape[0]))
            return nc
        elif column.dtype == bool:
            return column.astype(numpy.int64)

        return column

    if isinstance(table, pandas.Series):
        return pandas.Series(transform(table), name=table.name, index=table.index)
    else:
        if _pandas_version_under0p23:
            return table.apply(transform, axis=0, reduce=False)
        else:
            return table.apply(transform, axis=0, result_type='reduce')