TEC-DATA85-12 · Lesson 2 · 60 clock hours · lab
Data Pipeline: Cleaning, Transformation, and Exploratory Analysis
Objective. Students build a documented, reproducible Python or R data pipeline that cleans and merges their raw datasets, produces a validated analysis-ready file, and generates a complete exploratory data analysis (EDA) report with descriptive statistics and at least six publication-quality charts.
⚠ 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.
Data Pipeline: Cleaning, Transformation, and Exploratory Analysis
A data pipeline is the structured sequence of steps that moves raw data from its source to a form suitable for analysis. In professional practice, every step must be documented, version-controlled, and reproducible—meaning a colleague running your script on the same raw files should get the identical output. This lesson walks you through building that pipeline for your capstone project.
Why Reproducibility Matters
Reproducibility is a non-negotiable professional standard. If your analysis cannot be re-run by someone else, your conclusions cannot be trusted or audited. Store every script in a Git repository with meaningful commit messages. Commit after each major milestone—not just at the end. A repository with five or more commits shows reviewers that you worked iteratively, not all at once.
Step 1 — Data Cleaning
Raw data almost always contains errors. Your cleaning script must address four categories of problems:
Missing values. Decide whether to drop rows, impute with the mean or median, or flag the gap with a sentinel value. Document your choice and reason in a comment. In pandas: `df.dropna()`, `df.fillna()`, or `df['col'].median()`. In R tidyverse: `drop_na()`, `replace_na()`.
Outliers. Identify values that fall far outside the expected range. Common approaches include the interquartile range (IQR) method—flagging values below Q1 − 1.5×IQR or above Q3 + 1.5×IQR—and domain-knowledge thresholds. Never silently delete outliers; log them in a separate file and state your decision in a comment.
Data-type mismatches. A column of prices stored as strings will break arithmetic. Cast columns explicitly: `df['price'] = pd.to_numeric(df['price'], errors='coerce')` in pandas, or `as.numeric()` in R. After casting, re-check for newly introduced missing values.
Duplicate records. Duplicates inflate counts and skew aggregations. Use `df.duplicated().sum()` to find them and `df.drop_duplicates()` to remove them, then verify the row count matches expectations.
Write every decision as a code comment. A classmate will attempt to re-run your script as a peer code review. If your script fails or produces different output on their machine, that is a reproducibility failure—not their problem.
Step 2 — Merging Datasets
Most real projects combine more than one source. You will perform SQL joins either inside Python using SQLAlchemy or psycopg2, or directly in PostgreSQL.
Choose the correct join type for your business question:
- INNER JOIN — keeps only rows with matching keys in both tables.
- LEFT JOIN — keeps all rows from the left table; fills unmatched right-side columns with NULL.
- FULL OUTER JOIN — keeps all rows from both tables.
After the join, write a data dictionary: a spreadsheet that lists every retained column, its data type, valid value range, and any transformation applied. A complete data dictionary—100% of retained columns defined—is required to pass this lab. This directly supports CompTIA Data+ domain 2 (Data Mining) competencies and Google Data Analytics Certificate data-cleaning skills.
Step 3 — Exploratory Data Analysis (EDA)
EDA is the process of summarizing and visualizing data to understand its structure before modeling. Work in a Jupyter Notebook or R Markdown file so that code, output, and prose live together.
Descriptive statistics must include:
- Central tendency: mean, median, mode.
- Spread: standard deviation, variance, range, IQR.
- Shape: skewness (positive skew = tail extends right; negative skew = tail extends left).
In pandas: `df.describe()` gives count, mean, std, min, quartiles, and max. Add `df.skew()` for skewness.
Required visualizations (at least six):
1. Histogram — distribution of a single numeric variable.
2. Box plot — spread and outliers for one or more groups.
3. Scatter plot — relationship between two numeric variables.
4. Correlation heat map — pairwise correlations across numeric columns.
5. Bar chart — comparison of a numeric measure across categories.
6. Your choice — any additional chart that reveals something meaningful in your data.
Use Matplotlib, Seaborn, ggplot2, or a comparable library. Every chart must be publication quality: labeled axes, a title, a legend where applicable, and readable font sizes. Beneath each chart, write one paragraph interpreting what the chart reveals—not just what it shows, but what it means for your research question.
Data Safety and Ethical Handling
Data pipelines can expose personally identifiable information (PII). Before cleaning, check whether your dataset contains names, addresses, Social Security numbers, or other PII. If it does, apply masking or anonymization before sharing files with classmates during peer review. Never commit raw files containing PII to a public repository. Follow your institution's data-use policy and any applicable regulations governing the data source.
Passing This Lab
The instructor will run your cleaning script independently on the raw source files. It must execute without errors and produce a validated output file. Your data dictionary must define every retained column. Your EDA notebook must contain at least six charts, each with a written interpretation. The lab is graded on a 20-point rubric; you need 15/20 to advance. Your Git repository must show a minimum of five meaningful commits.
Key terms10
ReproducibilityThe property of an analysis or script that allows a different person to run the same code on the same raw data and obtain the identical result.
Data pipelineA documented, ordered sequence of steps that ingests raw data, cleans and transforms it, and delivers a validated, analysis-ready dataset.
ImputationThe process of replacing missing values with a calculated or assumed substitute, such as the column mean, median, or a domain-specific constant.
IQR (Interquartile Range)The difference between the 75th percentile (Q3) and the 25th percentile (Q1) of a dataset; used as a robust measure of spread and for flagging outliers.
Data dictionaryA structured reference document that defines every column in a dataset, including its name, data type, valid value range, and any transformation applied.
SkewnessA statistical measure of the asymmetry of a distribution; positive skewness indicates a right-leaning tail, negative skewness a left-leaning tail.
Exploratory Data Analysis (EDA)An analytical approach that uses descriptive statistics and visualization to summarize the main characteristics of a dataset before formal modeling.
SQL joinA SQL operation that combines rows from two or more tables based on a related column; common types include INNER, LEFT, RIGHT, and FULL OUTER joins.
Correlation heat mapA grid visualization where each cell shows the pairwise correlation coefficient between two numeric variables, using color intensity to indicate strength and direction.
Version control (Git)A system that records changes to files over time so that specific versions can be recalled; Git is the industry-standard tool, with GitHub and GitLab as common hosting platforms.
Worked examples4
1. A column called 'annual_salary' has 200 rows. After loading the CSV, df['annual_salary'].dtype shows 'object'. Running pd.to_numeric(df['annual_salary'], errors='coerce') produces 12 NaN values where there were none before. How many rows remain after dropping the newly missing values, and what percentage of the data is lost?
- Start with 200 total rows and 0 original missing values in the column.
- After coercion, 12 rows become NaN (these were non-numeric strings that could not be converted).
- Dropping those rows: 200 − 12 = 188 rows remain.
- Percentage lost = (12 / 200) × 100 = 6.0%.
Answer: 188 rows remain; 6.0% of the data is lost. Document in a code comment that 12 non-numeric salary values were coerced to NaN and dropped, and log those rows to a separate CSV for review before finalizing the decision.
2. A numeric column has Q1 = 45 and Q3 = 115. Using the standard IQR outlier rule (values below Q1 − 1.5×IQR or above Q3 + 1.5×IQR), calculate the lower and upper fences.
- Calculate IQR: IQR = Q3 − Q1 = 115 − 45 = 70.
- Calculate 1.5 × IQR: 1.5 × 70 = 105.
- Lower fence: Q1 − 105 = 45 − 105 = −60.
- Upper fence: Q3 + 105 = 115 + 105 = 220.
Answer: Lower fence = −60; upper fence = 220. Any value below −60 or above 220 is flagged as a potential outlier under the standard IQR rule.
3. Table A has 1,000 rows and Table B has 800 rows. They share a key column 'customer_id'. An INNER JOIN on customer_id returns 650 rows. How many rows from Table A had no match in Table B, and how many rows from Table B had no match in Table A?
- INNER JOIN returns only rows with matching keys in both tables: 650 matched pairs.
- Rows in Table A with no match in Table B: 1,000 − 650 = 350.
- Rows in Table B with no match in Table A: 800 − 650 = 150.
- A LEFT JOIN on Table A would return 1,000 rows (650 matched + 350 unmatched, with NULLs for Table B columns).
Answer: 350 rows from Table A had no match in Table B; 150 rows from Table B had no match in Table A. Choose your join type deliberately based on which unmatched rows matter to your analysis question.
4. A dataset of 10 values has a mean of 52 and a median of 41. A new analyst says the data is approximately symmetric. Is that correct? What does the relationship between mean and median suggest about skewness direction?
- In a symmetric distribution, mean and median are approximately equal.
- Here, mean (52) > median (41), a difference of 11 points.
- When the mean exceeds the median, high-value outliers are pulling the mean upward, producing a right-leaning (right, or positive) tail.
- Conclusion: the distribution is positively skewed, not symmetric.
Answer: The analyst is incorrect. A mean of 52 that is noticeably larger than a median of 41 indicates positive (right) skewness. The analyst should verify this with a histogram or skewness statistic before proceeding.
The math in this lesson1
Learners compute rows lost and percent of data dropped after type coercion.
7.RP.3
In class: Students write a step-by-step cleaning script in Python (pandas) or R (tidyverse) stored in a Git repository; the script handles missing values, outliers, data-type mismatches, and duplicate records using explicit, commented code; a classmate attempts to re-run the script on the same raw files and confirms reproducibility as part of a peer-code-review checklist. · Students merge datasets using SQL joins executed inside Python (SQLAlchemy/psycopg2) or directly in PostgreSQL, producing a single analysis-ready table; they write a data dictionary spreadsheet defining every retained column, its data type, valid range, and any transformation applied—directly supporting CompTIA Data+ domain 2 (Data Mining) and Google Data Analytics Certificate data-cleaning competency areas. · Students conduct EDA using descriptive statistics (central tendency, spread, skewness) and produce at least six visualizations (histogram, box plot, scatter plot, correlation heat map, bar chart, and one chart of their own choice) using Matplotlib, Seaborn, ggplot2, or equivalent; they write a one-paragraph interpretation beneath each chart in a Jupyter or R Markdown notebook that will become a chapter of the final report.
Materials: Python 3 with pandas, NumPy, Matplotlib, Seaborn, SQLAlchemy; or R with tidyverse, ggplot2, R Markdown; PostgreSQL; Git and GitHub (or GitLab); Jupyter Notebook or VS Code; peer code-review checklist; data dictionary template; CompTIA Data+ domain 2 reference; Google Data Analytics Certificate Process and Analyze phase competency list.
Check: Instructor runs the student's cleaning script independently on the raw source files; script must execute without errors and produce a validated output file. Data dictionary must define 100% of retained columns. EDA notebook must contain at least six charts, each with a written interpretation; graded on a 20-point rubric—15/20 minimum to advance. Git repository must show meaningful commit history (minimum five commits).
Practice check8
Answer each question, then check it. Nothing is recorded; this is your own practice.
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.