Editor

Build the Extraction Layer

Advanced · Write the code · from Build a Simple ETL Pipeline: Extract, Transform, Load

From the lesson: Step 1: Extract Data from Multiple Sources

The "E" in ETL stands for Extract. In the real world, this means pulling data from databases, APIs, files, and services. Since we can't access real APIs in the browser, we'll simulate multiple data sources using Python data structures - dictionaries for API-like data and multi-line strings for CSV-like data.

Read this part of the lesson

Create two extraction functions:

1. extract_from_api(data) - takes a list of dictionaries, prints "Extracted N records from API", returns the list.

2. extract_from_csv(csv_string) - takes a CSV string, parses it into a list of dicts (converting id to int and amount to float), prints "Extracted N records from CSV", returns the list.

Combine results from both sources into all_records. Print the total count as "Total records: N" and print each record's id and name.

# Source 1: API-like data
api_data = [
{'id': 1, 'name': 'Alice Johnson', 'email': 'alice@example.com', 'amount': 150.00},
{'id': 2, 'name': 'Bob Smith', 'email': 'bob@example.com', 'amount': 230.50},
{'id': 3, 'name': 'Charlie Brown', 'email': '', 'amount': 75.00},
]
# Source 2: CSV-like data
csv_data = """id,name,email,amount
4,Diana Prince,diana@example.com,320.00
5,Eve Wilson,,180.25
6,Frank Miller,frank@example.com,95.50"""
def extract_from_api(data):
pass
def extract_from_csv(csv_string):
pass
# Combine and print results

More ETL Pipeline exercises

All Python exercises · 50 practice problems · Practical Projects quiz