🚧 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 › Python and R for Data Science & Analytics › Lesson 6
TEC-DATA85-03 · Lesson 6 · 12 clock hours · practice

Exploratory Data Analysis with pandas and NumPy

Objective. Students perform a structured exploratory data analysis on a real tabular dataset using pandas and NumPy, producing a summary report that describes shape, distributions, missingness, and outliers.

⚠ 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 Exploratory Data Analysis?

Exploratory Data Analysis (EDA) is the structured practice of summarizing, visualizing, and questioning a dataset before building models or drawing conclusions. The goal is to understand what the data actually contains — its shape, distributions, missing values, and anomalies — so that every downstream decision rests on solid ground. EDA is a core competency tested by the Google Data Analytics Certificate, the IBM Data Science Professional Certificate, and CompTIA Data+.

Loading Data with pandas

pandas is the standard Python library for working with tabular data. You load a CSV file into a DataFrame with `pd.read_csv('filename.csv')`. Once loaded, call `df.shape` to confirm the number of rows and columns, and `df.dtypes` to see how pandas has interpreted each column's data type. A quick `df.head()` lets you inspect the first few rows.

For each column, four pandas methods form the backbone of your data dictionary:

Write one paragraph per column in a Markdown cell. State the column's name, data type, number of unique values, the most common value (for categoricals) or the descriptive statistics (for numerics), and the count of missing values. This is your data dictionary, and it is the artifact that stakeholders can read without opening your code.

Computing Statistics with NumPy

NumPy operates on arrays and is highly efficient for numerical computation. After isolating numeric columns with `df.select_dtypes(include='number')`, you can compute:

Flagging Outliers with the Three-Sigma Rule

A common, defensible method is to flag any observation whose value falls more than three standard deviations from the column mean. For a column named `response_time`:

```python

mean = np.mean(df['response_time'])

std = np.std(df['response_time'], ddof=1)

df['outlier_response_time'] = (np.abs(df['response_time'] - mean) > 3 * std)

```

The result is a Boolean column: `True` means the value is a potential outlier. Always inspect flagged rows manually — an outlier may be a data-entry error, a legitimate extreme event, or evidence of a second population in your data. Do not delete outliers without documenting your reasoning.

A note on the IQR method: Some analysts prefer flagging values below Q1 − 1.5×IQR or above Q3 + 1.5×IQR. Both methods are valid; document which you chose and why.

Writing the EDA Narrative

A Jupyter Markdown cell can contain formatted text alongside your code. Your five-paragraph narrative must cover:

1. Source — Where did the data come from? State the URL, agency, and date accessed.

2. Structure — How many rows and columns? What time period or geography does it cover?

3. Key distributions — Which numeric columns are skewed? Which categories dominate? Mention specific numbers.

4. Missing-data pattern — Which columns have missing values? Is missingness random or concentrated in specific categories or time periods?

5. Stakeholder questions — Pose two concrete, answerable questions. For example: "Does average response time differ by neighborhood?" or "Which request type generates the most repeat calls?"

Writing the narrative forces you to translate code output into plain language — a professional skill valued in every data role.

Data Integrity and Professional Ethics

Before publishing any EDA, verify that your dataset's terms of use permit analysis and sharing. Open-government datasets (data.gov, city open-data portals) are generally public, but confirm the license. Never re-publish personally identifiable information (PII). If a column contains names, addresses, or phone numbers, note its presence in your data dictionary but mask or drop values in any shared artifact.

Workspace Safety Note

Data science work is primarily a computer workstation environment. Follow your institution's acceptable-use policy for networked systems. When downloading files from external sources, save them to a designated project folder — do not run files from unknown sources, as malicious code can be embedded in data files. Use virtual environments to isolate package dependencies and prevent conflicts across projects.

Key terms8

DataFrameThe primary pandas data structure: a two-dimensional table with labeled rows and columns, similar to a spreadsheet or SQL table.
Descriptive statisticsNumerical summaries — such as mean, median, standard deviation, and quartiles — that describe the central tendency and spread of a variable.
Missing value (null)A cell in a dataset that contains no recorded observation, represented in pandas as NaN (Not a Number) and detected with isnull().
OutlierAn observation that falls far from the bulk of the data; commonly defined as a value more than three standard deviations from the mean or outside the IQR fence.
Interquartile range (IQR)The difference between the 75th percentile (Q3) and the 25th percentile (Q1); measures the spread of the middle 50 percent of a distribution and is resistant to extreme values.
Sample standard deviationA measure of spread calculated by dividing the sum of squared deviations from the mean by n−1 (ddof=1 in NumPy); used when data represent a sample rather than the full population.
Data dictionaryA written reference document that defines each column in a dataset: its name, data type, meaning, range of values, and count of missing entries.
EDA narrativeA plain-language written summary of exploratory findings, intended to communicate dataset characteristics and analytical questions to a non-technical stakeholder.

Worked examples4

1. A numeric column called 'wait_days' has these ten values: 2, 5, 3, 8, 4, 6, 3, 5, 4, 40. Compute the mean, median, and sample standard deviation.
  1. Sum all values: 2+5+3+8+4+6+3+5+4+40 = 80. Divide by 10: mean = 80 / 10 = 8.0 days.
  2. Sort values: 2, 3, 3, 4, 4, 5, 5, 6, 8, 40. With 10 values (even count), the median is the average of the 5th and 6th values: (4 + 5) / 2 = 4.5 days.
  3. Compute each squared deviation from the mean (8.0): (2−8)²=36, (5−8)²=9, (3−8)²=25, (8−8)²=0, (4−8)²=16, (6−8)²=4, (3−8)²=25, (5−8)²=9, (4−8)²=16, (40−8)²=1024. Sum = 1164.
  4. Sample variance = 1164 / (10−1) = 1164 / 9 ≈ 129.33. Sample standard deviation = √129.33 ≈ 11.37 days.
Answer: Mean = 8.0 days, Median = 4.5 days, Sample standard deviation ≈ 11.37 days. The large gap between mean and median signals the value 40 is pulling the mean upward.
2. Using the same 'wait_days' column (mean = 8.0, std ≈ 11.37), apply the three-sigma rule to determine whether the value 40 is flagged as a potential outlier.
  1. Calculate the upper threshold: mean + 3 × std = 8.0 + 3 × 11.37 = 8.0 + 34.11 = 42.11 days.
  2. Calculate the lower threshold: mean − 3 × std = 8.0 − 34.11 = −26.11 days (not meaningful here since wait days cannot be negative).
  3. Check the value 40: |40 − 8.0| = 32. Is 32 > 3 × 11.37 = 34.11? No, 32 < 34.11.
  4. Conclusion: The value 40 is NOT flagged by the three-sigma rule with this small sample. It would be flagged by the IQR method: Q1 = 3, Q3 = 5.75, IQR = 2.75, upper fence = 5.75 + 1.5 × 2.75 = 9.875; 40 > 9.875.
Answer: 40 is not flagged by the three-sigma rule (threshold ≈ 42.11) but is flagged by the IQR fence method (upper fence ≈ 9.875). This illustrates why documenting your chosen method matters.
3. A dataset has 500 rows and 8 columns. The 'zip_code' column shows 47 unique values and 12 missing entries. Write the two pandas expressions that produce these two facts.
  1. To count unique values in 'zip_code': df['zip_code'].nunique() — this returns 47.
  2. To count missing values in 'zip_code': df['zip_code'].isnull().sum() — this returns 12.
  3. To get both facts for all columns at once, use df.nunique() and df.isnull().sum() on the full DataFrame and read the 'zip_code' row from each result.
Answer: df['zip_code'].nunique() returns 47; df['zip_code'].isnull().sum() returns 12. These two values belong in the data dictionary paragraph for 'zip_code'.
4. For the values 10, 20, 30, 40, 50, compute the IQR using NumPy's percentile function.
  1. Q1 = 25th percentile of [10, 20, 30, 40, 50]. With 5 values, Q1 = 17.5 (NumPy's default linear interpolation: position = 0.25 × 4 = 1.0, value = 20; using linear: 10 + 0.25×(20−10) = 12.5 — NumPy linear gives 17.5 using its internal index formula; np.percentile([10,20,30,40,50], 25) = 17.5).
  2. Q3 = 75th percentile: np.percentile([10,20,30,40,50], 75) = 42.5.
  3. IQR = Q3 − Q1 = 42.5 − 17.5 = 25.0.
Answer: IQR = 25.0. In code: iqr = np.percentile(arr, 75) - np.percentile(arr, 25).

The math in this lesson2

Learners compute mean, median and standard deviation and see how an outlier skews the mean.
S-ID.2S-ID.3
Brush up in the math halls at newSchoolWorks.com:
In class: Load a publicly available dataset (e.g., a US city open-data file such as 311 service requests) into a pandas DataFrame; use describe(), value_counts(), isnull().sum(), and nunique() to build a written data dictionary with one paragraph per column. · Use NumPy to compute mean, median, standard deviation, and the interquartile range for all numeric columns; flag any values more than three standard deviations from the mean as potential outliers and add a Boolean outlier column. · Write a five-paragraph EDA narrative (in a Jupyter Markdown cell) that states the dataset's source, structure, key distributions, missing-data pattern, and two specific questions a stakeholder might answer with the data.
Materials: Jupyter Notebook, pandas documentation (pandas.pydata.org), NumPy documentation (numpy.org), publicly available open dataset, lab log
Check: EDA notebook submitted with all code cells executed; data dictionary covers every column; outlier flagging logic is correct for at least one verified outlier; narrative addresses all five required points — maps to Google Data Analytics and IBM Data Science EDA competencies.

Practice check8

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

Data preparation and cleaning
1. Which pandas method returns the count of missing values for every column in a DataFrame in a single call?
Statistical analysis and data distribution
2. A data analyst uses the three-sigma rule to flag outliers. A column has mean = 50 and sample standard deviation = 10. Which value would be flagged as a potential outlier?
Statistical analysis and data distribution
3. When computing sample standard deviation with NumPy, why should you set ddof=1?
Data governance and ethics
4. A dataset downloaded from a city open-data portal includes a column containing residents' full names. What is the most appropriate first action before sharing your EDA notebook?
Exploratory data analysis
5. Which pandas method is most useful for understanding the distribution of a categorical column such as 'complaint_type'?
Statistical analysis and data distribution
6. An analyst notes that a column's mean is much higher than its median. What does this most likely indicate?
Data communication and reporting
7. In a Jupyter Notebook EDA narrative, a student writes: 'The dataset was obtained from data.cityofnewyork.us on 2024-09-01 and contains 1.2 million rows and 41 columns representing 311 service requests from January through August 2024.' Which required narrative element does this sentence most directly satisfy?
Statistical analysis and data distribution
8. A data analyst computes Q1 = 20 and Q3 = 50 for a numeric column. What is the IQR, and what is the upper outlier fence using the 1.5×IQR rule?
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.