Data Validation
Advanced · Write the code · from Build a Simple ETL Pipeline: Extract, Transform, Load
From the lesson: Step 2: Validate the Extracted Data
Data from the real world is messy. Emails might be missing, amounts might be negative, names could be empty strings. Before transforming data, you should validate it and flag any problems. Some issues are warnings (missing email), while others are errors (negative amount).
Read this part of the lessonWrite a function validate_records(records) that checks each record for:
1. name must not be empty or missing - if invalid, add to errors list.
2. amount must be a positive number - if invalid, add to errors list.
3. email should not be empty - if empty, add to warnings list.
Return a tuple: (valid_records, errors, warnings) where valid_records excludes records with errors (warnings are OK).
Test with sample data that includes at least one invalid record (empty name or negative amount). Print "Valid: N", "Errors: N", "Warnings: N".
More ETL Pipeline exercises
- Build the Extraction LayerAdvanced
- Clean and Standardize DataAdvanced
- Enrich Records with Derived FieldsAdvanced
- Load Data into SQLiteAdvanced
- Verify and Analyze Loaded DataAdvanced
- The Complete ETLPipeline ClassAdvanced
All Python exercises · 50 practice problems · Practical Projects quiz