Enrich Records with Derived Fields
Advanced · Write the code · from Build a Simple ETL Pipeline: Extract, Transform, Load
From the lesson: Step 4: Transform - Derive New Fields
Beyond cleaning, transformations often add new fields that make the data more useful for analysis. These derived fields are calculated from existing data. For example, you might categorize amounts into tiers, extract the domain from email addresses, or add processing timestamps.
Read this part of the lessonWrite a function enrich_records(records) that adds these derived fields to each record:
1. amount_tier - "low" if amount < 100, "medium" if 100–250, "high" if > 250.
2. email_domain - the part after @ in the email (e.g., "example.com").
3. name_parts - number of words in the name.
4. processed - set to True.
Return the enriched list. Test with sample data and print each record showing all new fields.
More ETL Pipeline exercises
- Build the Extraction LayerAdvanced
- Data ValidationAdvanced
- Clean and Standardize DataAdvanced
- Load Data into SQLiteAdvanced
- Verify and Analyze Loaded DataAdvanced
- The Complete ETLPipeline ClassAdvanced
All Python exercises · 50 practice problems · Practical Projects quiz