ColumnTransformer routes different column groups through different preprocessing pipelines, then combines their outputs. A typical dataset sends continuous features through scaling and categorical features through encoding, so each type receives an appropriate transformation. section 8.1.4 section 8.3.2
A practical preprocessing workflow is:
- Separate continuous and categorical column names. section 8.1.4
- Build a pipeline for each group—for example, median imputation followed by StandardScaler for continuous data, and missing-value imputation followed by an encoder for categorical data. section 8.3.2
- Pass those pipelines and their column lists to ColumnTransformer, optionally preserving unspecified columns with remainder='passthrough'. section 8.1.4
- Fit the combined preprocessor on training data, then call transform on held-out data; do not fit preprocessing on the test set. section 8.1.4 section 8.3.2
Mixed-feature credit classification
For the Australian Credit Approval data, scaling continuous columns and one-hot encoding categorical columns expanded 14 input features to 38. A RandomForestClassifier reached 89.855% hold-out accuracy after transformation. section 8.1.4
from sklearn.compose import ColumnTransformer
ct = ColumnTransformer(
transformers=[('continuous', #1
preprocess_continuous, cont_features),
('categorical', #2
preprocess_categorical, cat_features)],
remainder='passthrough') #3
Inspect a complete ColumnTransformer configuration assigning separate continuous and categorical pipelines, with passthrough for remaining columns. section 8.1.4

