In Different Columns, Different Steps you gave ColumnTransformer a list of lines, each one (name, what to do, which columns). It sent each group of columns its own way and joined the pieces back into one wide table of numbers, with names that remember the route each column took. Here you build that junction yourself, in plain Python.
Task: write column_transform(table, routes, remainder="drop"). It learns every step from table and transforms table in one go, as fit_transform does, and returns a tuple (names, rows).
The table. table is a dict from column name to that column's list of values, like the dict you hand to pd.DataFrame. Its keys are in the table's column order, and every list has the same length.
The routes. routes is a list of (name, method, columns) tuples, where columns is a list of column names and method is one of:
| method | learns from the column | output |
|---|---|---|
"standard" | the average and the spread (divide by , as StandardScaler does) | one column: each becomes |
"minmax" | the smallest value and the largest value | one column: each becomes |
"onehot" | the different values in the column, sorted alphabetically | one column per value, holding 1.0 in rows with that value and 0.0 elsewhere |
The remainder. A column that no route names is the remainder. remainder="drop" (the default) throws it away, "passthrough" copies it through unchanged, and a method name sends every remainder column through that method.
The output.
routes. Within a route they follow the order of that route's columns list, which need not be the table's order. Remainder columns come last, in the table's order.route__column for a scaled or passed-through column, route__column_value for a one-hot column. Remainder columns use remainder as their route name.rows has one list per table row, and every value in it is a float rounded to 4 decimal places.In every test, a column sent to "standard" or "minmax" holds numbers that are not all equal, and a column passed through untouched holds numbers. The first visible test is the lesson's fruit table.