This project implements a complete data cleaning and preprocessing pipeline starting from a raw dataset (dirty_dataset.csv).
The objective is to transform inconsistent and noisy data into a clean, structured dataset suitable for analysis and machine learning.
The pipeline performs:
- Data validation
- Text cleaning
- Type conversion
- Deduplication
- Feature engineering
- User scoring
.
├── dirty_dataset.csv
├── clean_dataset_final.csv
├── pulizia_csv.py
└── README.mdThe dataset contains multiple data quality issues such as invalid identifiers, noisy text, inconsistent formats, and missing values.
The user_id column is validated using a UUID pattern.
Invalid, null, or malformed identifiers are removed to ensure data integrity.
Text fields are cleaned by:
- Removing noise (
NULL,n/a,xxx) - Removing special characters
- Normalizing whitespace
- Converting empty values to
NaN
Categorical values are standardized:
- Country values →
IT - Categories →
Tech,Home,Fashion
This ensures consistency in grouping and analysis.
Columns are converted to appropriate types:
- Numeric:
age,rating,reviews_count - Boolean:
returned - Invalid values are handled (e.g., negative age → removed)
The purchase_amount column is reconstructed to handle:
- Decimal commas (
"12,50"→12.50) - Special values (
"free"→0)
A new column is_free is added to explicitly mark free transactions.
Dates are parsed from multiple formats into a unified datetime format.
Logical consistency is enforced by removing records where:
last_login < signup_date
Duplicates are handled in two steps:
- Exact duplicates removal
- Fuzzy matching (via
rapidfuzz)
A blocking strategy improves performance by grouping similar records before comparison. The most complete record is retained.
New features are derived:
| Feature | Description |
|---|---|
| days_since_signup | Days since registration |
| days_since_last_login | Days since last login |
| is_active_user | Active within last 30 days |
Users with anomalous data are identified:
- Invalid or missing age
- Invalid email format
- Missing or non-numeric rating
These issues are stored in the error_type column.
A score (0–100) is computed based on:
- Purchase amount (40%)
- Login recency (30%)
- Number of reviews (20%)
- Rating (10%)
All variables are normalized before weighting.
Missing values are analyzed across:
- Country
- Category
This helps detect non-random missing patterns and potential bias in the dataset.
clean_dataset_final.csvThe dataset is:
- Cleaned
- Standardized
- Deduplicated
- Enriched with features and scores
pip install pandas numpy rapidfuzz
python pulizia_csv.py- Visualization of missing values (heatmaps)
- Machine learning models
- Automated ETL pipeline
- API-based validation
This project demonstrates a full data preprocessing workflow, transforming raw data into a reliable dataset ready for advanced analysis.
Developed as part of a Data Cleaning and Data Analysis exercise.