← Books

Books · Data science

Python for Data Analysis

Wes McKinney · 2022

The pandas creator’s own guide to wrangling data in Python — NumPy, pandas, matplotlib and Jupyter, taught through real datasets. 3rd edition. Logged as a full chapter-by-chapter course.

Why I read it

Once students can write Python, the next question is always "what do I do with it?" — and for most of them the honest answer is data: a spreadsheet, a CSV export, a log file. Wes McKinney wrote pandas, so this is the tool explained by the person who built it, with the reasoning behind the design rather than just the API.

My copy was the 2012 first edition, which turned out to be a lesson of its own: its code is Python 2 and pandas 0.9 (.ix, xrange, easy_install), and a lot of it no longer runs. So this course follows the 3rd edition's outline and writes every example for current pandas.

Chapters

Each chapter is split into short sessions — concept, key terms, a worked example and exercises — with one interactive demo per chapter. 5 of 15 are up; the rest are stamped in progress until their page exists.

Code Chapter Status

C1

Preliminaries

What kind of data the book means, why Python, the seven core libraries, and a modern conda-forge setup.

C4

NumPy Basics

The ndarray, views vs. copies, boolean and fancy indexing, ufuncs, np.where, and a vectorised random walk.

C5

Getting Started with pandas

Series, DataFrame and Index; reindexing, loc vs. iloc, label alignment, sorting, and descriptive statistics.

C6

Data Loading, Storage & File Formats

read_csv and friends, JSON, HTML and XML, binary formats like Parquet and Excel, web APIs, and databases.

In progress

C7

Data Cleaning & Preparation

Missing data, duplicates, mapping and replacing values, binning, outliers, string methods, and categoricals.

In progress

C8

Data Wrangling: Join, Combine & Reshape

Hierarchical indexing, merge and join, concat, and reshaping with stack, unstack, pivot and melt.

In progress

C9

Plotting & Visualization

The matplotlib figure/axes model, plotting straight from pandas, and seaborn for statistical charts.

In progress

C10

Data Aggregation & Group Operations

Split-apply-combine with groupby, agg, apply and transform, pivot tables, and cross-tabulation.

In progress

C11

Time Series

Timestamps and periods, date ranges and frequencies, time zones, resampling, and moving-window functions.

In progress

C12

Introduction to Modeling Libraries

Handing pandas data to models: Patsy formulas, statsmodels, and scikit-learn.

In progress

C13

Data Analysis Examples

Five real datasets end to end — Bitly, MovieLens, US baby names, the USDA food database, and FEC donations.

In progress

A

Advanced NumPy

ndarray internals and strides, C vs. Fortran order, broadcasting rules, structured arrays, and performance tips.

In progress

B

More on the IPython System

Command history, the shell, magic commands like %timeit and %debug, and profiling.

In progress

Verdict

Worth the time — but read it as a reference you work through at a keyboard, not a book you read on the sofa. Chapters 5, 7, 8 and 10 (pandas basics, cleaning, wrangling, groupby) are the core; together they cover most of what a real analysis needs.

The shift that matters is mental: stop writing loops over rows and start thinking in whole columns, aligned by their index.

Skip the first edition. The ideas hold up; the code doesn't.

Read it free

McKinney publishes the full 3rd edition free online at wesmckinney.com/book, and the example datasets live in the pydata-book repository. The book was written against Python 3.10; everything on these pages is checked against current pandas (3.0), and works on 2.x unless a page says otherwise.