A lightweight Python library for cleaning, auditing, and validating tabular data. It helps data scientists, analysts, and engineers quickly identify data quality issues, clean datasets using simple rules, and generate reports.
Data quality problems often consume more time than analysis itself. Missing values, duplicate records, inconsistent column names, and invalid entries can silently affect downstream models and business decisions.
Datra provides a simple workflow for understanding and improving dataset quality before analysis or machine learning.
With Datra, you can:
- Audit datasets to identify quality issues.
- Clean data using configurable rules.
- Validate datasets against business rules.
- Generate JSON and HTML quality reports.
- Work directly with Pandas DataFrames or CSV and Excel files.
- Dataset profiling
- Missing value analysis
- Duplicate detection
- Outlier detection (IQR-based)
- Rule-based data validation
- Automated data quality scoring
- Configurable data cleaning
- Column name standardization
- Support for Pandas DataFrames
- CSV and Excel file support
- JSON and HTML report generation
- Save cleaned datasets directly to disk
Install Datra from PyPI:
pip install datraOr install the latest development version:
git clone https://github.com/raphaelj1/datra.git
cd datra
pip install -e .from datra import clean
cleaned = clean(
"patients.csv",
drop_duplicates=True,
fill_numeric="median",
fill_categorical="mode",
standardize_columns=True,
)from datra import Audit
audit = Audit("patients.csv")
print(audit.profile)
print(audit.score)rules = {
"Age": {
"min": 0,
"max": 120,
},
"Gender": {
"allowed": [
"Male",
"Female",
],
},
}
report = audit.validate(rules)The clean() function applies one or more cleaning operations to a dataset and returns a new DataFrame. It accepts either a Pandas DataFrame or the path to a CSV or Excel file.
from datra import clean
cleaned = clean(
"patients.csv",
drop_duplicates=True,
fill_numeric="median",
fill_categorical="mode",
standardize_columns=True,
)rules = {
"duplicates": {
"drop": True,
},
"missing": {
"numeric": "median",
"categorical": "mode",
},
"columns": {
"standardize": True,
},
}
cleaned = clean("patients.csv", rules=rules)clean(
"patients.csv",
drop_duplicates=True,
output="cleaned_patients.xlsx",
)Create an audit object to inspect dataset quality.
from datra import Audit
audit = Audit("patients.csv")Retrieve individual quality checks.
audit.profile
audit.completeness
audit.uniqueness
audit.outliers
audit.scoreOr access all audit results at once.
audit.resultsValidate datasets against custom business rules.
rules = {
"Age": {
"min": 0,
"max": 120,
},
"Patient ID": {
"unique": True,
},
"Gender": {
"allowed": [
"Male",
"Female",
],
},
}
report = audit.validate(rules)Validation returns a structured report describing which checks passed, which failed, and the number of violations for each rule.
Build a data quality report as a Python dictionary.
from datra import Audit
audit = Audit("patients.csv")
report = audit.build_report()Save the report as JSON.
audit.save_report(
format="json",
)Or save it as an HTML report.
audit.save_report(
format="html",
)Datra supports both Pandas DataFrames and common tabular file formats.
| Input | Supported |
|---|---|
| Pandas DataFrame | ✅ |
| CSV | ✅ |
| Excel (.xlsx) | ✅ |
| Excel (.xls) | ✅ |
| Format | Supported |
|---|---|
| JSON | ✅ |
| HTML | ✅ |
| 🚧 Planned |
datra/
├── datra/ # Library source code
├── examples/ # Example usage
├── tests/
├── pyproject.toml
├── README.md
└── LICENSE
Planned improvements include:
- PDF report generation
- Command-line interface (CLI)
- Additional cleaning operations
- Additional validation rules
- More data quality checks
- Interactive HTML reports
- Support for additional file formats
Contributions, feature requests, and bug reports are welcome.
If you would like to contribute:
- Fork the repository.
- Create a new feature branch.
- Commit your changes.
- Open a pull request.
Please ensure all tests pass before submitting a pull request.
This project is licensed under the MIT License.