ETL and ELT in Python
Jake Roach
Data Engineer
$$
... are responsible for moving data from a source to a destination, and transforming it somewhere along the way.
$$
pandas
$$
$$
$$
$$
def load(data_frame, target_table):
# Some custom-built Python logic to load data to SQL
data_frame.to_sql(name=target_table, con=POSTGRES_CONNECTION)
print(f"Loading data to the {target_table} table")
# Now, run the data pipeline
extracted_data = extract(file_name="raw_data.csv")
transformed_data = transform(data_frame=extracted_data)
load(data_frame=transformed_data, target_table="cleaned_data")
Extracting data from raw_data.csv
Transforming data to remove 'null' records
Loading data to the cleaned_data table
...
def transform(source_table, target_table):
data_warehouse.run_sql("""
CREATE TABLE {target_table} AS
SELECT
<field-name>, <field-name>, ...
FROM {source_table};
""")
# Similar to ETL pipelines, call the extract, load, and transform functions
extracted_data = extract(file_name="raw_data.csv")
load(data_frame=extracted_data, table_name="raw_data")
transform(source_table="raw_data", target_table="cleaned_data")
$$
ETL and ELT in Python