Objective. Students will apply a set of specified transformation rules — null substitution, data-type casting, deduplication, and a business-rule filter — to a staging dataset and produce a clean output file that passes automated validation.
This lesson, its worked examples and its practice questions has not yet been verified by an industry-certified professional or by a certification or approval body. It is a study draft and may contain errors. Do not use it as instructions for work on a job site or on live equipment. Always follow your instructor, your supervising professional, and current official references and regulations.
VoTechWorks program approval and accreditation are still in progress. Credentials are issued only by the certifying bodies named in each program, after their own exams.
The transformation stage is the most complex part of any ETL pipeline. Extracting raw data from a source is relatively mechanical; loading clean data into a target is straightforward. What happens in between — cleaning, casting, deduplicating, and applying business rules — determines whether the data warehouse or operational database becomes an asset or a liability. This lesson walks through each category of transformation logic you will apply in today's lab.
Raw operational data almost always contains defects: missing values, inconsistent formats, duplicate records, and values that violate business constraints. If these defects reach the target database, every downstream query, report, and decision that touches that data is compromised. The DAMA DMBOK2 defines data quality in terms of dimensions such as completeness, consistency, accuracy, and timeliness. Your transformation script is the enforcement point for all of those dimensions before data ever enters the target schema.
A null in a required field means the downstream application cannot rely on that column. Two strategies exist: reject the row entirely, or substitute a configured default value. Which strategy you apply depends on the business rule in the data dictionary. For example, a `customer_region` field might allow a default of `'UNKNOWN'` so the record is not lost, while a `transaction_amount` field with a null must be rejected because no safe default exists. Always read the data dictionary before writing substitution logic. Hard-coding defaults in the script body rather than a configuration section makes the script brittle and harder to audit.
Source systems frequently store numbers as strings and dates in whatever format the original developer chose. Before a row can be loaded into a typed relational column, every value must be cast to the correct type. In Python with pandas, `pd.to_numeric()` with `errors='coerce'` converts a column to float and sets unconvertible values to `NaN`, which you can then catch as a validation failure. For date columns, `pd.to_datetime()` with a `format` parameter and `errors='coerce'` performs the same service. After casting, rows where coercion produced `NaN` in a non-nullable column must be logged and rejected — not silently dropped.
Date formats in source data are notoriously inconsistent: `01/15/2024`, `2024-01-15`, `15-Jan-24`, and `January 15, 2024` all represent the same day. ISO 8601 (`YYYY-MM-DD`) is the international standard and the format most relational databases accept unambiguously. Once a date column is successfully cast to a pandas `datetime64` type, calling `.dt.strftime('%Y-%m-%d')` produces the correct string representation for export. If the cast fails, the row is rejected with reason code `INVALID_DATE`.
A primary key uniquely identifies each row in the target table. If the staging file contains two rows with the same primary key, loading both violates the constraint and will cause a database error or silent data overwrite, depending on the load strategy. Deduplication logic must decide which copy to keep — typically the first occurrence or the most recently timestamped — and must log all discarded duplicates with reason code `DUPLICATE_PK`. In pandas, `DataFrame.duplicated(subset=['primary_key_column'], keep='first')` identifies the rows to reject.
Beyond structural cleaning, most pipelines enforce domain-specific constraints. Examples include:
Each violated rule produces a rejected row with a specific reason code such as `OUT_OF_RANGE` or `MISSING_SHIP_DATE`. Reason codes must match the codes defined in the data dictionary so that downstream data-quality reporting is consistent.
Every rejected row must be written to a separate error file — not deleted silently. The error file should contain at minimum: the original row data, the reason code, and ideally the row number from the source file. This audit trail is essential for compliance, for root-cause analysis, and for returning bad records to the source system for correction. In a production environment, silent data loss is a data governance failure. DAMA DMBOK2 Chapter 13 treats traceability of rejected records as a core data quality practice.
After your transformation script runs, the instructor-provided validation script checks the clean output file against the target schema and counts violations. Your goal is zero schema errors. The rejection rate — rejected rows divided by total input rows — must also fall at or below the instructor-specified threshold (five percent for this lab). A rate above that threshold suggests either a systemic defect in the source data that must be escalated, or a bug in your transformation logic that is incorrectly rejecting valid rows. Investigate both possibilities before resubmitting.
Although this is a software lab with no electrical or mechanical hazards, safe data handling practices apply. Never write transformation output to the same file path as your input; a script error could truncate the original staging file, which you cannot recreate. Work on a copy of the instructor CSV, keep the original read-only. Commit your script to version control (or save numbered versions) before each test run so you can roll back a change that worsens results. Treat the data dictionary as authoritative — do not invent business rules not specified there.
Professional ETL developers rarely produce a passing transformation script on the first run. Read the validation output carefully, trace each class of error back to the relevant section of your script, fix one category at a time, and re-run. Systematic iteration is faster than random edits.
Answer each question, then check it. Nothing is recorded; this is your own practice.
A free tech program — complimentary, as our commitment to get America working. Help us build VoTechWorks. Tell us what works, what doesn’t, and what you want to learn.