Verify and Analyze Loaded Data
Advanced · Predict the output · from Build a Simple ETL Pipeline: Extract, Transform, Load
From the lesson: Step 6: Query and Verify the Loaded Data
After loading data, you should always verify it. Run queries to check row counts, look for unexpected NULLs, and generate summary statistics. This is the quality assurance step that catches loading errors before anyone uses the data.
Read this part of the lessonStudy the code below. It loads data into SQLite and runs verification queries. What will be printed? Pay close attention to the SQL aggregations and GROUP BY results.
import sqlite3
conn = sqlite3.connect(':memory:')
cursor = conn.cursor()
cursor.execute('CREATE TABLE customers (id INTEGER PRIMARY KEY, name TEXT, email TEXT, amount REAL, amount_tier TEXT, email_domain TEXT)')
data = [
(1, 'Alice', 'alice@a.com', 150.0, 'medium', 'a.com'),
(2, 'Bob', 'bob@b.com', 50.0, 'low', 'b.com'),
(3, 'Charlie', 'charlie@a.com', 320.0, 'high', 'a.com'),
(4, 'Diana', 'diana@b.com', 80.0, 'low', 'b.com'),
]
cursor.executemany('INSERT INTO customers VALUES (?, ?, ?, ?, ?, ?)', data)
conn.commit()
cursor.execute('SELECT COUNT(*) FROM customers')
print(f'Total: {cursor.fetchone()[0]}')
cursor.execute('SELECT amount_tier, COUNT(*), SUM(amount) FROM customers GROUP BY amount_tier ORDER BY amount_tier')
for tier, count, total in cursor.fetchall():
print(f'{tier}: {count} customers, ${total:.0f}')
More ETL Pipeline exercises
- Build the Extraction LayerAdvanced
- Data ValidationAdvanced
- Clean and Standardize DataAdvanced
- Enrich Records with Derived FieldsAdvanced
- Load Data into SQLiteAdvanced
- The Complete ETLPipeline ClassAdvanced
All Python exercises · 50 practice problems · Practical Projects quiz