Load Data into SQLite
Advanced · Write the code · from Build a Simple ETL Pipeline: Extract, Transform, Load
From the lesson: Step 5: Load into SQLite
The "L" in ETL means loading transformed data into its final destination. For us, that's a SQLite database. We'll create a table that matches our enriched record structure and insert all records in a batch.
Read this part of the lessonWrite a function load_to_database(records) that:
1. Creates an in-memory SQLite database.
2. Creates a customers table with columns: id (INTEGER PRIMARY KEY), name (TEXT), email (TEXT), amount (REAL), amount_tier (TEXT), email_domain (TEXT).
3. Inserts all records using executemany().
4. Commits and returns the connection.
Then query the database to verify: print the row count and all rows. Print "Loaded N records into database".
More ETL Pipeline exercises
- Build the Extraction LayerAdvanced
- Data ValidationAdvanced
- Clean and Standardize DataAdvanced
- Enrich Records with Derived FieldsAdvanced
- Verify and Analyze Loaded DataAdvanced
- The Complete ETLPipeline ClassAdvanced
All Python exercises · 50 practice problems · Practical Projects quiz