Clean messy real-world datasets with safe, explainable defaults before ML.
Project description
datacleaner - ML-safe data cleaning library
datacleaner cleans messy real-world tabular datasets with safe defaults, explicit behavior, and explainable outputs. It is designed for ML workflows where target integrity matters: the main clean pipeline does not modify the target column when target_column is provided.
Key Features
- Safe cleaning pipeline with defensive guards
- Target column protection across all cleaning steps
- Explicit target handling via handle_target()
- Real-world numeric parsing support (currency symbols, percentages, commas)
- Outlier handling with cap/remove strategies
- Column reduction with safety rollbacks
- Detailed report with shape and integrity metadata
- Validated on 30+ datasets across classification and regression
Installation
pip install datacleanr
Package name on PyPI: datacleanr Import name in code: datacleaner
Quick Example
from datacleaner import handle_target, clean
df, target_meta = handle_target(df, "target")
cleaned_df, report = clean(df, target_column="target", return_report=True)
Target Handling
Why target is not modified automatically:
- In supervised ML, target values are labels. Silent mutation can corrupt training targets.
- The main clean function is intentionally conservative and avoids target rewrites.
How to use handle_target:
- Use handle_target before clean when target contains missing values.
- This function is explicit and returns transparent metadata about what it did.
Safe defaults:
- strategy="auto" defaults to dropping rows with missing target
- If target missing ratio is above threshold, rows are dropped regardless of strategy
- Fill is only used for low-missing targets when explicitly requested
Returned metadata fields:
- target_missing_ratio
- action: none | rows_dropped | filled
- rows_removed
- fill_value (only when action is filled)
- filled_count (only when action is filled)
Pipeline Overview
clean runs this sequence:
- missing value handling
- duplicate removal
- datatype cleaning
- outlier handling
- text standardization
- column selection
- correlation reduction
- safety checks and reporting
Example Report Output
{
"final_shape": [1200, 24],
"rows_removed_pct": 2.5,
"columns_removed_pct": 8.3,
"integrity_warnings": []
}
Validation
- Tested on 30+ datasets from multiple domains
- Includes classification and regression datasets
- Includes noisy variants with missing values, mixed text/number fields, currency, percentages, and comma-formatted numerics
- No target corruption observed with target_column protection and explicit handle_target preprocessing
- No crash regressions in stress validation
Design Philosophy
- Conservative over aggressive
- Transparency over automation
- Safety over convenience
Future Improvements
- Configurable policy profiles per domain
- More advanced locale-aware numeric parsing
- Benchmarking against common sklearn preprocessing baselines
License
MIT License. See LICENSE.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file datacleanr-0.1.3.tar.gz.
File metadata
- Download URL: datacleanr-0.1.3.tar.gz
- Upload date:
- Size: 21.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
662eaf3541e012df6c53417f95d3c15bad0c80032a2a7ef112fd4658bd1fcfa8
|
|
| MD5 |
db520c158294a643da113515a2b0872b
|
|
| BLAKE2b-256 |
dad2faf66419c57908e7f78a92130f4b2cdf2e0f03638e44a7d6fb96b6728ec1
|
File details
Details for the file datacleanr-0.1.3-py3-none-any.whl.
File metadata
- Download URL: datacleanr-0.1.3-py3-none-any.whl
- Upload date:
- Size: 22.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ec56c422f29face761a392231a367b8c9bc7ea9693433654bcc319b529a46897
|
|
| MD5 |
5c81d81cb7c5f512e9e9dba570b76e87
|
|
| BLAKE2b-256 |
3f0b900538441fea19b82ee000c777194e7c3923eaa5d2bb9bc6daa59a873f37
|