Skip to content
Why this exists

Intro

Same cleaning rules. Every batch.

A scikit-learn transformer for pandas. It fits imputation, outlier, category, and schema rules on X_train, then reuses them unchanged for validation, test, and production. No test-set peeking, no re-learning, and no silent schema drift.

Python
from data_cleaner import DataCleaner

cleaner = DataCleaner()
cleaner.fit(X_train)

# Fitted on X_train only:
# medians, categories, bounds, schema
train_clean = cleaner.transform(X_train)
test_clean = cleaner.transform(X_test)

# Reuse the fitted rules in production.
prod_clean = cleaner.transform(X_prod)

cleaner.decision_log()

fit() learns from training data. transform() returns a new frame and never mutates the caller’s DataFrame.

Pandas is excellent at expressing a cleaning operation once. The hard part is doing it twice with the same parameters: once for training and once for inference.

leak_safe.py
# This learns a different rule for every batch, including the test set.
df["age"] = df["age"].fillna(df["age"].median())

# This learns once on training data, then reuses the stored rule.
cleaner = DataCleaner(CleanerConfig()).fit(X_train)
X_test_clean = cleaner.transform(X_test)

The fitted cleaner holds the medians, modes, IQR bounds, category values, and schema. transform() applies them without learning from the frame you pass in.

Terminal
pip install universal-data-cleaner

The distribution is universal-data-cleaner; the import is data_cleaner.

clean.py
import pandas as pd
from data_cleaner import CleanerConfig, DataCleaner

train = pd.DataFrame(
    {
        "age": [34, 41, None, 29],
        "salary": [70_000, 82_000, 91_000, 55_000],
        "dept": ["IT", "HR", "IT", None],
        "joined": pd.to_datetime(
            ["2022-01-03", "2021-11-20", "2023-04-01", "bad-date"],
            format="mixed",
            errors="coerce",
        ),
    }
)

config = CleanerConfig(
    datetime_columns=("joined",),
    add_missing_indicators=True,
    drop_constant_columns=True,
)

cleaner = DataCleaner(config).fit(train)
train_clean = cleaner.transform(train)
print(cleaner.cleaning_summary())

fit() learns from train. transform() returns a new frame and never mutates the caller’s DataFrame. The same fitted object is safe for validation, test, and production batches.

StageCallLearned fromSafe for test data?
Trainingcleaner.fit(X_train)X_train only—
Training outputcleaner.transform(X_train)Stored training state—
Evaluationcleaner.transform(X_test)Stored training stateYes
Servingcleaner.transform(X_new)Stored training stateYes

The rule is simple: fit once on training data, then only transform everywhere else. Do not create a second cleaner for test or production data.

AreaIncluded
CleaningNumeric coercion, median / mean / constant imputation, IQR capping, categorical mode / constant imputation, boolean coercion, datetime parsing and calendar features, missing indicators, constant-column dropping
IngestionSafe CSV, Excel, and optional Parquet reads with contract-driven coercion, identifier protection, date/boolean guards, and an ingestion report
ReportingCleanerReport combining profile, contract drift, validation, ingestion, and decisions, plus a data-cleaner audit CLI
ValidationExpectations plus cross-column, conditional, grouped, combination-uniqueness, and arithmetic rules with bounded, privacy-safe row diagnostics
DriftStatistical drift against a reusable reference profile: PSI, Wasserstein distance, missingness and category deltas
OperationsDecision logs, manifests, stable fingerprints, joblib save / load, and scikit-learn Pipeline, clone, and get_feature_names_out compatibility

Install the package, fit one cleaner, and transform a test batch without re-learning. The quickstart is the shortest path from a messy DataFrame to a reusable preprocessing step: start with the quickstart.