Data Analysis with Python: From Raw Data to Real-World Insights
BOOK 2 · INTRODUCTION · CHAPTER 1

Start here: run, investigate and explain

On this page

This book teaches you to turn a question into checked data, a defensible analysis and a reproducible explanation. NumPy supplies numerical arrays; Pandas supplies labelled tables. Mathematics helps you understand what the operations mean. Short visual checks help you see patterns and mistakes. Projects bring these skills together before you proceed to advanced visualization, machine learning and deep learning.

You need basic Python: variables, lists, dictionaries, conditions, loops, functions, imports and file paths. You should be able to explain a short function and read an error message. If a prerequisite is unfamiliar, use Book 1’s matching lesson or another introductory Python resource. You do not need a machine-learning framework, paid account, GPU or AI assistant for this book.

Set up the experiment folder

Download the experiment package from Companion resources and extract it into a folder you can edit. Keep its data, notebooks, code and outputs folders together. The examples use saved inputs, so a changing website cannot prevent you from doing the core experiments. Acquisition scripts are optional ways to obtain a later snapshot; later data may have different values.

The learner package was installed and tested with Python 3.13.5 and Pandas 2.2.3. Use a Python 3.13 interpreter for this recorded setup. In a terminal opened in the extracted project folder, create an environment and install the dependencies:

python3 -m venv .venv
# macOS or Linux
source .venv/bin/activate
# Windows PowerShell, instead of the activation above
.venv\Scripts\Activate.ps1
python -m pip install -r requirements.txt
python -m jupyterlab

Run the activation instruction for your operating system, not both. A managed computer may provide its own environment instead; use its approved setup. The verification record identifies the exact Python and package versions used for this edition. Run the diagnostic before assuming that your environment matches:

import sys
import numpy as np
import pandas as pd
import matplotlib
print(sys.version.split()[0])
print(np.__version__, pd.__version__, matplotlib.__version__)
assert np.array([2, 3]).sum() == 5
assert pd.Series([2, 3]).mean() == 2.5
3.13.5
2.1.3 2.2.3 3.10.0

Open the chapter notebook from the notebook browser. Its first cell locates the experiment root from the notebook’s folder and sets the working directory. This is essential path setup, not a special replacement for Python’s print. If it reports that the project folder is missing, extract the whole package rather than copying one notebook away from its data.

Analysis lifecycle; return to earlier stages when evidence changesQuestionAcquireValidateExploreExplainReproduce

Follow one experimental cycle

Read the question and define the observation. Predict a small result before running the code. Run one example, inspect its output, change one input, and explain the difference. Then attempt the chapter exercises without opening the worked answers. Finally, transfer the operation to a different table or question.

A result is not understood merely because the cell ran. You should be able to state the input, relevant assumption, operation, output unit and one limitation. For example, sum() may add visits across sessions; it does not automatically count distinct people. An error is also evidence: inspect what assumption failed instead of adding unrelated code until the message disappears.

Read code, formulas and diagrams together

In a formula, identify each symbol and its unit before substituting numbers. In an array, name each axis. In a table, define the observation key. In a figure, inspect the axes, units, missing observations and group support. The selectable diagrams expose text and elements so you can discuss a particular row, line or label precisely; selection does not change the source data.

The original cultural examples use fictional countries and invented quantities where explicitly stated. The museum, penguin and population projects use attributed source snapshots. Do not merge the evidential status of these examples: an invented table demonstrates a method, while an observational table also requires attention to how its values were collected.

Use exercises and worked answers

Each chapter has at least three exercises: a focused operation, a debugging or interpretation task, and an independent transfer. The prompt supplies the input and required output. Try it first, record your reasoning, then use the separate worked-answer page. Alternative implementations are welcome when they preserve the stated assumptions and pass the checks.

When your result differs, compare the observation set, key, axis, missing-value policy and units before comparing formatting. A correct-looking number obtained with the wrong denominator is not a correct answer. Record the correction in your notebook so that the mistake becomes a reusable lesson.

Use AI as an optional tutor

A useful prompt names the task, your attempt and the boundary of help: “I expected three rows from this join but received six. Ask me one question about key uniqueness before suggesting code.” Another is: “Critique my conclusion using only the supplied table. Identify unsupported claims; do not invent causes.”

Do not ask a tool to supply evidence that the dataset does not contain. Verify proposed changes with a small hand-checkable case and the source documentation. Keep credentials and confidential records out of prompts. You can complete every core experiment without AI.

Demonstrate progress

After NumPy, you should predict shapes and explain axes, views and numerical summaries. After Pandas, you should validate keys, clean documented issues, join safely and reshape intentionally. After applied analysis, you should explain comparisons, gaps, uncertainty and evaluation boundaries. After the projects, another reader should be able to run your analysis and trace a reported claim back to its observations.

Expertise develops through repeated independent work on unfamiliar data. The book supplies the concepts, experiments, solutions and feedback structure; your explanations and project revisions supply evidence of mastery.

Teaching edition · verified experiments · PDF and EPUB editions not generated.