A generic, reusable Python pipeline that automatically profiles, cleans, transforms, and validates ANY tabular CSV or Excel dataset β making it ML-ready in one command.
ANY RAW CSV / EXCEL DATASET
β
Auto Column Type Detection
β
Profiling & Missing Value Analysis
β
Cleaning & Normalization
β
Outlier Detection (IQR)
β
Date Feature Engineering
β
Boolean & Categorical Encoding
β
Scikit-Learn Pipeline (Scale + Encode)
β
Validation (PASS / FAIL)
β
CLEANED CSV + ML-READY MATRIX + REPORTS + CHARTS
git clone https://github.com/imsurya26/universal-data-preprocessing.git
cd universal-data-preprocessingpip install -r requirements.txt# CSV file
python preprocess.py --input your_dataset.csv
# Excel file (first sheet by default)
python preprocess.py --input your_dataset.xlsx
# Excel β choose specific sheet
python preprocess.py --input your_dataset.xlsx --sheet "Sheet2"| Argument | Short | Default | Description |
|---|---|---|---|
--input |
-i |
dataset.csv |
Path to input CSV or Excel file |
--output |
-o |
processed_data/ |
Output directory for all results |
--sheet |
-s |
0 |
Excel sheet name or index (ignored for CSV) |
--handle-outliers |
False |
Cap extreme outliers using IQR bounds | |
--no-scaling |
True |
Disable StandardScaler on numerical columns | |
--no-date-features |
True |
Skip date feature extraction | |
--include-identifiers |
False |
Include ID columns in ML matrix | |
--include-free-text |
False |
Include free-form text in ML matrix |
# Standard run
python preprocess.py --input sales_data.csv
# Cap outliers + custom output folder
python preprocess.py --input data.csv --output results/ --handle-outliers
# Disable scaling (e.g. for tree-based models)
python preprocess.py --input data.csv --no-scaling
# Include identifiers in ML matrix
python preprocess.py --input data.csv --include-identifiersAfter running, you get:
processed_data/
βββ cleaned_dataset.csv β Human-readable cleaned data
βββ ml_ready_dataset.csv β Encoded + scaled ML-ready matrix
βββ preprocessing_report.csv β Per-column transformation log
βββ preprocessing_summary.txt β Full before/after text summary
βββ reports/figures/
βββ missing_values.png β Missing values before vs after
βββ numerical_distributions.png
βββ numerical_boxplots.png β Outlier diagnostic
βββ correlation_heatmap.png
Also saved directly to the project root:
cleaned_dataset.csvml_ready_dataset.csvpreprocessing_report.csvpreprocessing_summary.txt
The script automatically detects column types using value-based heuristics β not just pandas dtype:
| Detected Type | Logic |
|---|---|
identifier |
Column name contains id/email/name, email pattern, EMP001-style codes, or high uniqueness |
boolean |
Values are subset of {yes, no, true, false, y, n, 0, 1} |
datetime |
70%+ of values parse successfully as dates |
numerical |
Numeric or numeric strings ($75,000, 50%) after cleaning |
categorical |
Short, low-cardinality string values |
text |
Long strings / avg word count > 3 (e.g. reviews, notes) |
Detects and converts all common missing representations to NaN:
NaN, None, NULL, null, N/A, na, ?, -, "", whitespace-only strings
| Column Type | Strategy |
|---|---|
| Numerical | Median imputation |
| Categorical | Mode imputation |
| Boolean | Mode imputation |
| Datetime | Forward fill β Backward fill |
| Identifier / Text | "Missing" placeholder |
For every numerical column, computes: Q1, Q3, IQR, Lower Bound, Upper Bound, Outlier Count
Outlier capping is off by default β use --handle-outliers to enable it.
Numerical β SimpleImputer(median) β StandardScaler
Categorical β SimpleImputer(most_frequent) β OneHotEncoder(handle_unknown='ignore')
Boolean β 0 / 1 conversion
Datetime β year, month, day, day_of_week, quarter features
After every run the script prints a full validation summary:
========== VALIDATION ==========
Rows before: 1000
Rows after: 987
Duplicates before: 13
Duplicates after: 0
Missing values before: 45
Missing values (Clean): 0
Missing values (ML): 0
Infinite values: 0
Invalid values: 0
Validation status: PASS
================================
Automatically saved to reports/figures/:
| Plot | Description |
|---|---|
missing_values.png |
Bar chart: missing counts before vs after |
numerical_distributions.png |
KDE histograms for each numerical column |
numerical_boxplots.png |
Boxplots for outlier inspection |
correlation_heatmap.png |
Pearson correlation matrix heatmap |
You can also edit the defaults at the top of preprocess.py:
DATA_PATH = "dataset.csv"
OUTPUT_DIR = "processed_data"
HANDLE_OUTLIERS = False
EXTRACT_DATE_FEATURES = True
EXCLUDE_IDENTIFIERS = True
EXCLUDE_FREE_TEXT = True
SCALE_NUMERICAL = Truepandas>=2.0.0
numpy>=1.24.0
scikit-learn>=1.2.0
matplotlib>=3.7.0
seaborn>=0.12.0
openpyxl # for .xlsx Excel files
xlrd # for legacy .xls Excel files
Install all at once:
pip install -r requirements.txt
pip install openpyxl xlrduniversal-data-preprocessing/
βββ preprocess.py β Main preprocessing pipeline (all-in-one)
βββ dataset.csv β Sample test dataset with edge cases
βββ requirements.txt β Python dependencies
βββ README.md β This file
βββ cleaned_dataset.csv β Generated output
βββ ml_ready_dataset.csv β Generated output
βββ preprocessing_report.csv β Generated output
βββ preprocessing_summary.txt β Generated output
βββ processed_data/
βββ reports/figures/ β Generated diagnostic charts
Pull requests are welcome! If you find a bug or want to add a new feature (e.g. a new column type detector or imputation strategy), feel free to open an issue.
MIT License β free to use, modify, and distribute.
Surya β @imsurya26