TEC-DATA85-05 · Lesson 2 · 11 clock hours · lab
Profiling and Auditing Raw Data
Objective. Students will generate a comprehensive data-quality report for a provided dataset using pandas-profiling (ydata-profiling), R's skimr, and SQL COUNT/NULL queries, then summarize findings in a written audit memo.
⚠ 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.
What Is Data Profiling?
Before you clean any dataset, you need to understand what is actually in it. Data profiling is the process of examining a raw dataset to collect statistics and metadata about its structure, content, and quality. Profiling answers questions like: How many rows and columns are there? What data type is each column? How many values are missing? Are there duplicates? Are numeric distributions skewed or do they contain outliers? A data audit takes those findings one step further—it judges whether the data is fit for its intended purpose and communicates the results to stakeholders.
Profiling before cleaning is standard practice. Jumping straight into transformation without understanding the data leads to missed problems, incorrect assumptions, and errors that can invalidate an entire analysis.
Safety and Professional Responsibility
Data work carries its own professional safety obligations. Raw datasets frequently contain personally identifiable information (PII) such as names, addresses, inspection scores tied to specific businesses, or GPS coordinates. Before profiling any real dataset:
- Confirm you have authorization to access and process the data.
- Work only in approved, secured environments (never upload sensitive data to a public cloud notebook without explicit permission).
- Do not share profile reports outside the project team unless PII has been removed or masked.
- Follow your organization's data-governance and acceptable-use policies.
In this lab the city inspection CSV is a synthetic dataset provided by your instructor, so PII risk is low—but building these habits now matters for every real-world project you encounter.
Profiling with ydata-profiling in Python
`ydata-profiling` (formerly `pandas-profiling`) generates a detailed HTML report from a pandas DataFrame with just a few lines of code:
```python
import pandas as pd
from ydata_profiling import ProfileReport
df = pd.read_csv("city_inspections.csv")
profile = ProfileReport(df, title="City Inspections Profile", explorative=True)
profile.to_file("inspection_report.html")
```
The HTML report is organized into several sections you must learn to read:
- Overview – row and column counts, total missing cells, duplicate rows, and memory usage.
- Variables – per-column statistics. For numeric columns: mean, median, standard deviation, min, max, and a histogram. For categorical columns: number of distinct values, the most frequent value, and a bar chart.
- Interactions – scatter plots for pairs of numeric columns.
- Correlations – Pearson, Spearman, and Phik correlation matrices.
- Missing values – a heatmap showing which columns are missing values and whether missingness clusters together (a pattern suggesting data was collected or exported incorrectly).
- Warnings – automated flags such as high cardinality, near-zero variance, and columns that are highly correlated with another.
When you annotate findings, be specific. "Column `inspector_id` has 3,412 missing values (6.8 % of rows)" is a finding. "Some data is missing" is not.
Profiling in R with skimr and dplyr
`skimr` provides a compact, readable summary directly in the R console or in an R Markdown document:
```r
library(skimr)
library(dplyr)
df <- read.csv("city_inspections.csv")
skim(df)
```
`skim()` returns a grouped table showing, for each column: the number of missing values, the completion rate, and type-appropriate statistics (mean, SD, quantiles for numeric columns; counts and proportions for character columns). You can chain `dplyr` verbs before `skim()` to profile subsets:
```r
df |> filter(year == 2022) |> skim()
```
Comparing `skimr` output to the ydata-profiling report is a useful cross-check. Minor differences in statistics (for example, slightly different means) may reflect how each tool handles missing values during calculation—one may exclude NA by default while the other may not. Documenting discrepancies is part of building a trustworthy audit.
SQL COUNT and NULL Queries
When data lives in a relational database, SQL is the primary profiling tool. Two patterns are essential:
Count total rows and non-null values per column:
```sql
SELECT
COUNT(*) AS total_rows,
COUNT(inspector_id) AS non_null_inspector,
COUNT(*) - COUNT(inspector_id) AS missing_inspector
FROM city_inspections;
```
Find duplicate keys:
```sql
SELECT inspection_id, COUNT(*) AS cnt
FROM city_inspections
GROUP BY inspection_id
HAVING COUNT(*) > 1;
```
SQL profiling is fast on large tables and produces exact counts, which you can then verify against your Python and R outputs.
Writing the Audit Memo
A data audit memo translates technical findings into language a project manager can act on. The standard structure is:
1. Header – To, From, Date, Subject.
2. Purpose – one sentence stating why the audit was done.
3. Key Findings – numbered list of the top five quality issues, ordered by severity.
4. Business Impact – for each issue, explain what could go wrong in the analysis if the issue is not addressed.
5. Recommended Next Steps – specific, actionable cleaning tasks.
Avoid jargon. Write "14 % of inspection dates are missing" rather than "the temporal attribute exhibits a 14 % null prevalence." A project manager who is not a data scientist must be able to read your memo and make a prioritization decision.
Credential Relevance
Data profiling and auditing appear across all four credentials in this program. CompTIA Data+ covers data quality dimensions and documentation. Google Data Analytics emphasizes the inspect-and-clean cycle. IBM Data Science Professional includes exploratory data analysis as a core competency. Microsoft PL-300 requires understanding data-model quality before building Power BI reports. Mastering this single skill strengthens your preparation for all four exams.
Key terms10
Data profilingThe process of examining a dataset to collect statistics and metadata—such as row counts, data types, missing-value rates, and value distributions—before cleaning or analysis begins.
Data auditA structured assessment that evaluates whether a dataset meets quality standards for its intended use, documenting issues and recommending corrective actions.
ydata-profilingAn open-source Python library (formerly pandas-profiling) that generates an interactive HTML data-quality report from a pandas DataFrame in a few lines of code.
skimrAn R package that produces compact, human-readable summary statistics for each column in a data frame, grouped by data type.
Null / missing valueA cell in a dataset that contains no value; in SQL represented as NULL, in pandas as NaN. High null rates in a column can reduce statistical reliability.
CardinalityThe number of distinct values in a column. High-cardinality categorical columns (e.g., free-text fields) may indicate data-entry inconsistencies.
Personally Identifiable Information (PII)Any data that could identify a specific individual, such as name, address, or government ID number. PII requires special handling under data-governance and privacy policies.
Duplicate recordA row in a dataset that is identical or nearly identical to one or more other rows, often caused by import errors or system merges. Duplicates inflate counts and skew aggregates.
Correlation matrixA table showing pairwise statistical relationships between numeric columns. Values near +1 or −1 indicate strong linear relationships; values near 0 indicate little linear relationship.
Audit memoA short professional document that communicates data-quality findings, their business impact, and recommended next steps to a non-technical stakeholder.
Worked examples3
1. A column named `score` in a 50,000-row dataset has 3,750 null values. What is the null rate as a percentage, and how would you report it in an audit memo?
- Divide the number of nulls by the total row count: 3,750 ÷ 50,000 = 0.075
- Multiply by 100 to convert to a percentage: 0.075 × 100 = 7.5 %
- In the audit memo write: 'Column `score` is missing values in 3,750 rows (7.5 % of the dataset). Analyses that rely on inspection scores will be based on 92.5 % of records unless imputation or filtering is applied.'
Answer: The null rate is 7.5 %. Report it with both the count and the percentage, and note the share of complete records available for analysis.
2. You run a SQL duplicate-check query on `inspection_id` and receive the following results: inspection_id 10045 appears 3 times, inspection_id 10099 appears 2 times, and all other IDs appear once. The table has 50,000 rows total. How many rows should remain after removing duplicates, assuming you keep one row per inspection_id?
- Count the extra (duplicate) rows for each repeated ID: inspection_id 10045 has 3 rows, so 2 are extras; inspection_id 10099 has 2 rows, so 1 is extra.
- Total extra rows = 2 + 1 = 3
- Subtract extra rows from the total: 50,000 − 3 = 49,997
Answer: After deduplication, 49,997 rows remain.
3. The ydata-profiling report shows that column `violation_code` has 1,200 distinct values out of 50,000 rows. The column is categorical. Calculate the ratio of distinct values to total rows and explain what this means for data quality.
- Divide distinct values by total rows: 1,200 ÷ 50,000 = 0.024
- Express as a percentage: 0.024 × 100 = 2.4 %
- Interpret: A 2.4 % uniqueness ratio for a categorical code column is relatively high. Standard violation codes for a city program typically number in the dozens to low hundreds. Having 1,200 distinct values suggests possible free-text entry, inconsistent formatting (e.g., 'A-101' vs 'a101'), or data merged from multiple source systems.
- Flag this as a high-cardinality warning in the audit memo and recommend standardizing or mapping violation codes before aggregating by code.
Answer: The uniqueness ratio is 2.4 %. The high cardinality is a data-quality warning indicating likely inconsistent coding that should be investigated and standardized.
The math in this lesson1
Learners compute the percent of missing values from null counts over total rows.
7.RP.3
In class: Using a provided Jupyter notebook scaffold, students run ydata-profiling on a 50,000-row city inspection dataset, interpret every section of the HTML report (types, missing values, correlations, warnings), and annotate at least 15 specific findings. · Replicate the profile in R using skimr and dplyr; students compare the two tool outputs side by side and note any discrepancies in column statistics, documenting the comparison in an R Markdown file. · Write a two-page audit memo addressed to a fictional project manager that prioritizes the top five quality issues by severity, explains business impact in plain language, and recommends the next cleaning steps; peer-review using a provided rubric.
Materials: City inspection CSV (provided), Jupyter Lab, ydata-profiling library, RStudio, skimr and dplyr packages, audit memo template and peer-review rubric
Check: Audit memo is graded with the peer-review rubric; pass requires a score of 75 % or higher across four criteria: completeness of findings, accuracy of statistics, clarity of impact statements, and actionable recommendations.
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.