🚧 Under construction — VoTechWorks is being built. A free tech program — complimentary, as our commitment to get America working.
voTechWorksGrade 13 · a vocational technology learning center, by urbanicity
newSchoolWorks.com › VoTechWorks › Technology & Design › Data Science & Analytics › Data Cleaning and Preparation for Analysis › Lesson 7
TEC-DATA85-05 · Lesson 7 · 11 clock hours · practice

Reproducible Cleaning Pipelines and Version Control

Objective. Students will structure a multi-step cleaning workflow as a modular Python script with functions, a transformation log, and Git version control so that a peer can reproduce the cleaned output from raw data with a single command.

⚠ Pending professional review

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.

Why Reproducibility Matters in Data Cleaning

A cleaned dataset is only trustworthy if someone else — or your future self — can recreate it exactly from the raw data. When cleaning lives inside a single, linear notebook cell-by-cell, it is nearly impossible to audit, test, or hand off. A reproducible cleaning pipeline packages every transformation into named functions, records what happened in a log file, and tracks every change through version control. Employers, auditors, and teammates can then run one command and verify the result. This practice is foundational to professional data work and is tested across CompTIA Data+, the IBM Data Science Professional Certificate, and real-world hiring expectations.

Structuring a Cleaning Script as Modules

Refactoring a notebook into a Python script means replacing ad-hoc cells with named functions, each responsible for one logical step. A clean minimum structure looks like this:

A `main()` function calls these in order. Anyone reading the script sees the full pipeline in five lines. Each function should carry a docstring describing its inputs, outputs, and any assumptions — for example, which column names it expects. Clear function signatures and docstrings are not optional polish; they are the contract between your code and your collaborators.

Writing a Transformation Log

Python's built-in `logging` module lets you write timestamped records to a file without any third-party library. Configure it once near the top of your script:

```python

import logging

logging.basicConfig(

filename='pipeline.log',

level=logging.INFO,

format='%(asctime)s %(levelname)s %(message)s'

)

```

Then, inside each function, log what happened and how many rows were affected:

```python

logging.info(f'{dupes} duplicate rows removed')

logging.info(f'{reformatted} dates reformatted to ISO 8601')

```

The resulting log file is an audit trail — a permanent, human-readable record showing exactly what the pipeline did and when. If a downstream report looks wrong, the log is the first place you check. Logging counts and shapes (not cell-by-cell print statements) is a professional standard because it works the same way whether the script runs on your laptop or on a remote server.

Git Version Control for Data Pipelines

Git tracks every change to your code as a commit, a snapshot with a message explaining what changed and why. For a cleaning pipeline, a disciplined commit history might look like:

1. `init: add raw dataset and script scaffold`

2. `feat: implement load_raw with path validation`

3. `feat: implement clean_strings — strip whitespace, normalize case`

4. `feat: implement impute_missing — median fill for numeric cols`

5. `feat: implement export_clean and add logging config`

6. `docs: add README with run instructions`

Each commit message starts with a short verb phrase. Vague messages like `fixed stuff` are useless six months later. The commit history becomes documentation of your reasoning.

GitHub hosts a remote copy of the repository. Pushing to GitHub lets a partner clone your repo, run the pipeline, and check that their output matches yours — which is the definition of reproducibility.

Writing a Useful README

A README file (plain text or Markdown) lives in the repository root and answers three questions for any new reader:

1. What does this pipeline do? — one or two sentences.

2. What do you need to run it? — Python version, any libraries (`pandas`, etc.), and how to install them (e.g., `pip install -r requirements.txt`).

3. How do you run it? — the exact single command, such as `python clean_pipeline.py --input data/raw.csv --output data/clean.csv`.

A README that passes those three tests means a peer can reproduce your work with no verbal explanation from you.

Verifying Reproducibility with a Hash

To confirm two output files are identical, compare their SHA-256 hashes. A hash function converts any file into a fixed-length string; if even one byte differs, the hash changes completely. On the command line: `sha256sum output/clean.csv`. If your partner's hash matches yours, the reproduction is confirmed. This check removes subjectivity — you are not eyeballing rows, you are comparing a mathematical fingerprint.

Safety and Data Responsibility

Reproducible pipelines handle raw data that may contain personally identifiable information (PII). Never commit raw data files to a public GitHub repository. Add data files to `.gitignore` before your first commit, and store sensitive files on approved internal drives or private repositories only. Your organization's data governance policy — and federal and state privacy rules — apply regardless of how the data flows through your pipeline. Always confirm with your instructor or employer what may and may not be pushed to a cloud host.

Putting It Together

A reproducible cleaning pipeline combines three independent skills — modular code, audit logging, and version control — into one professional workflow. Each skill reinforces the others: functions make individual steps easy to log; logs make commits meaningful; commits make the README accurate. When your partner clones your repository and the hashes match, you have demonstrated that your data preparation is trustworthy, auditable, and shareable — the standard every data analytics employer expects.

Key terms8

Reproducible pipelineA data-cleaning workflow structured so that anyone can run it from raw input to finished output and get an identical result, with no manual steps.
RefactoringRestructuring existing code — such as converting notebook cells into named functions — without changing what the code does, to improve readability and reuse.
DocstringA string literal placed immediately after a function definition in Python that describes the function's purpose, parameters, and return value.
Transformation logA timestamped file written by the logging module that records each cleaning action and the number of rows or values affected.
Git commitA saved snapshot of changes to tracked files in a repository, accompanied by a descriptive message explaining what was changed and why.
SHA-256 hashA fixed-length cryptographic fingerprint of a file's contents; two files with matching SHA-256 hashes are byte-for-byte identical.
.gitignoreA text file in a Git repository that lists file patterns Git should not track or commit, commonly used to exclude raw data files and credentials.
Audit trailA chronological record — such as a log file or commit history — showing what actions were taken on data, by whom, and when.
In class: Refactoring workshop: students take a monolithic cleaning notebook from a previous lab and refactor it into a Python script with at least four named functions (load_raw, clean_strings, impute_missing, export_clean); instructor reviews function signatures and docstrings live. · Transformation-log implementation: students add a Python logging configuration to their script that writes a timestamped entry for every transformation (e.g., '342 duplicate rows removed', '17 dates reformatted'); they run the script and inspect the log file. · Git workflow exercise: students initialize a repository, make at least five commits with descriptive messages covering load, each cleaning step, and final export; write a README that explains how to run the pipeline; push to GitHub and swap repo URLs with a partner who clones and runs it, confirming the output matches.
Materials: Student laptops, Python 3, Git, GitHub accounts, prior lab dataset, VS Code or equivalent editor, logging module, provided script scaffold
Check: Partner must successfully reproduce the cleaned output (SHA-256 hash of output CSV matches) with no manual intervention; README and commit history reviewed by instructor; pass requires successful reproduction plus five or more meaningful commits and a complete README.

Practice check8

Answer each question, then check it. Nothing is recorded; this is your own practice.

Data preparation and cleaning (CompTIA Data+; IBM Data Science Professional)
1. A data analyst converts a Jupyter notebook into a Python script with separate functions for loading, cleaning, and exporting data. Which primary benefit does this refactoring provide?
Data preparation and wrangling (IBM Data Science Professional; Google Data Analytics)
2. Which Python standard-library module is used to write timestamped records of cleaning actions to a file during script execution?
Data governance and compliance (CompTIA Data+; IBM Data Science Professional)
3. A student pushes a cleaning pipeline to a public GitHub repository and accidentally includes the raw CSV file, which contains employee Social Security numbers. What is the most immediate corrective action?
Data quality and validation (CompTIA Data+)
4. After a partner clones a cleaning pipeline repository and runs it, they compute a SHA-256 hash of the output CSV. The hash matches the original author's recorded hash. What does this confirm?
Data engineering and workflow management (IBM Data Science Professional; Google Data Analytics)
5. Which Git commit message best follows professional conventions for a cleaning pipeline repository?
Data preparation and documentation (Google Data Analytics; CompTIA Data+)
6. A student writes a Python function `impute_missing(df)` but provides no docstring. What risk does this create?
Data wrangling and pipeline design (IBM Data Science Professional; Google Data Analytics)
7. In a cleaning pipeline's transformation log, an entry reads: '2024-03-15 10:42:07 INFO 89 rows dropped — nulls exceed 50 % threshold.' What logging level is being used, and what does it indicate?
Reproducibility and documentation (Google Data Analytics; IBM Data Science Professional)
8. A cleaning pipeline README states: 'Run python clean.py.' A new team member attempts this and receives a ModuleNotFoundError for pandas. Which README improvement would most directly prevent this problem?
Record this lesson on my transcript. Sign in with your key and enrollment email to record lessons (enroll free if you have no key). This page stays open to read and practise.