Open-source project
AllenDowney/ThinkStats2 avatar
AllenDowney/ThinkStats2

ThinkStats2: the notebooks and code behind a statistics book for Python programmers

Text and supporting code for Think Stats, 2nd Edition

4,239 stars11,282 forksJupyter NotebookGPL-3.0

At a glance

What is it?
ThinkStats2 holds the text, notebooks and supporting packages for Allen Downey's Think Stats, second edition, with two Jupyter notebooks per chapter, a thinkstats2 library and a thinkplot plotting module. It is a teaching repository rather than a library release, and its packaging metadata has drifted out of sync with the current tag.
Who is it for?
Use ThinkStats2 as a structured route into statistics for Python programmers, especially if you want the exercises and their solutions side by side with the text, and if you are willing to run Jupyter rather than import a library.
Can I use it commercially?
Yes, with conditions. GPL-3.0 is a copyleft licence: if you distribute software that includes it, you must release that software's source code under the same licence. Running it internally without distributing it does not trigger that obligation.
Is it still maintained?
Yes. The repository last received commits 13 days ago.
What is it written in?
Mainly Jupyter Notebook, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on October 23, 2026, and from our analysis. They are not legal advice.

Editorial analysis

What it is: a book with the code attached

Think Stats is described as an introduction to statistics and data science for Python programmers, aimed at people who already have basic Python skills and want to learn probability and statistics along with practical skills for working with data. The repository holds the text and the supporting code for the second edition.

The pedagogical choices are the interesting part. The book emphasises simple techniques you can use to explore real data sets and answer interesting questions, and it includes case studies using datasets from the National Institutes of Health and other sources. Many of the exercises are short programs that run an experiment, so the reader is not asked to take a formula on trust.

For an engineer picking this up, the value is the worked path from a raw dataset to a distribution, an effect size and a conclusion, with the code for every step in the repository. The audience is a Python programmer who wants to think statistically, not a statistician who wants to use a package.

One thing to keep in mind before you start. The repository is for the second edition, and the documentation states that the third edition of Think Stats is already available online, with a print version to follow. The code in this tree is therefore the second edition's code, not the current book's.

The repository layout: two packages, two notebook sets, and supporting directories

The top-level entries map closely onto the way the book is used. There is a code/ directory holding the chapter notebooks and a solutions/ directory holding the solution notebooks, a book/ directory for the text, plus examples/, homeworks/ and workshop/ directories for content that is not tied to a chapter.

The library itself is split into two packages, and setup.py lists them explicitly:

python
packages=['thinkstats2', 'thinkplot']

thinkstats2 holds the statistical functions the book builds up, and thinkplot holds the plotting helpers used by the notebook examples. The examples/ directory adds a set of standalone notebooks that go beyond the chapters, including an Economist Brexit dataset as a CSV file, a Mann-Whitney notebook, a central limit theorem notebook, a gender bias example, an ROC curve notebook and a skew test notebook.

Supporting files are the usual ones for a maintained teaching repository: a Makefile, an environment.yml for conda, requirements.txt and requirements-dev.txt, a setup.py, a CONTRIBUTING.md, a _config.yml for the GitHub Pages site, and a .github/ directory. The homepage is the GitHub Pages build of the book, so the repository doubles as the publication site.

Running the notebooks: Colab first, Anaconda or pip locally

The documentation's first suggestion is that the easiest way to work with the code is to run it on Colab, a free service that runs Jupyter notebooks in a web browser. Every chapter has two Colab links: one for the examples from the chapter, and one for the solutions to the exercises.

The local route is a matter of downloading the notebooks individually from GitHub or taking the whole repository as a Zip file of the master branch. The documentation also records the tool the book was written with: Anaconda, a free Python distribution that includes all the packages needed to run the code, and which by default installs at user level so no administrative privileges are required.

If you prefer pip, the dependency list is short but wide:

text
jupyter
numpy
matplotlib
plotly
seaborn
scipy
statsmodels
tables

The Makefile wraps that install:

bash
	$(PYTHON_INTERPRETER) -m pip install -r requirements.txt

Note what is missing from that list: no version pins at all. Nothing in requirements.txt constrains numpy, scipy or statsmodels to a version that the notebooks were written against, which is the first thing to be aware of when a cell fails to behave the way the book describes.

The Makefile targets, and the one test that is switched off

The Makefile is small and worth reading, because it encodes the working assumptions of the project. The interpreter is plain python, the target Python version is 3.10, and the environment target creates a named conda environment:

bash
	conda create --name $(PROJECT_NAME) python=$(PYTHON_VERSION) -y

Quality control runs through flake8 and black, with the lint target checking and the format target rewriting:

bash
	flake8 code
	black --check --config pyproject.toml code
bash
	black --config pyproject.toml code

The test target is the part that tells you how this repository is actually verified. It does not run a unit test suite in the usual sense. It executes the notebooks:

bash
	cd solutions; pytest --nbmake chap*soln.ipynb
	cd code; pytest --nbmake chap*ex.ipynb
	cd code; python thinkstats2_test.py

So correctness is defined as the notebooks running without error, which is a strong check on the code but says nothing about whether a statistical result is right. And one test is deliberately excluded, with a comment in the Makefile explaining that thinkplot_test is not run because it hangs on MacOS and Windows. A plotting test that deadlocks on two of the three major desktop platforms is a real limitation, and it is left in the tree as a commented-out line rather than fixed.

Setup metadata that no longer matches the release

The packaging file is the weakest part of the repository, and anyone who runs pip install . should look at it first.

It imports from distutils.core, and distutils was removed from the standard library in Python 3.12, so the file will not import on a current interpreter without a compatibility shim. It hardcodes version='2.0.0' while the published release is v2.2.1. Its url field points at the ThinkBayes2 repository, a different book by the same author, and its license field names LICENSE.txt while the repository actually ships a file called LICENSE.

None of that breaks the primary workflow, because the documentation steers you to Colab, to the Zip download, or to Anaconda, and the Makefile drives the install through requirements.txt rather than through setup.py. But it does mean the repository cannot be treated as an installable package in good faith, and a fork that wants to publish it would have to fix the metadata first.

The practical guidance, then, is to treat this as a set of notebooks rather than a library. Install the dependencies into a dedicated environment, clone or download the tree, and run the notebooks. If you want the thinkstats2 and thinkplot packages importable in your own project, expect to point PYTHONPATH at the checkout instead of relying on the setup metadata.

The licence story differs between the code and the book

Two licences are in play, and they do not match. The licence recorded for the repository is GPL-3.0, which covers the code in the tree, including the thinkstats2 and thinkplot packages.

The book itself is under a Creative Commons licence. The documentation states that this means you are free to copy, distribute and modify it, as long as you attribute the source and do not use it for commercial purposes. That is a different set of conditions from GPL-3.0, in particular the non-commercial restriction, which the GPL does not have and which the Creative Commons terms add.

So the code in thinkstats2/ and thinkplot/ is copyleft, and the text in book/ carries attribution and non-commercial conditions. A team that wants to reuse the plotting helpers inside a commercial product has to read the LICENSE file and decide for itself, and this is not legal advice, just the reason the distinction is worth flagging before code from this repository ends up in a product.

On maintenance, the repository is not archived, the last push was on 2026-10-10, and the single published release, v2.2.1, carries the same date. There is a CONTRIBUTING.md and a .github/ directory, so the project has the shape of a maintained repository even though most of the recent activity is the third edition of the book rather than the code in this tree.

Editorial conclusion

Use ThinkStats2 as a structured route into statistics for Python programmers, especially if you want the exercises and their solutions side by side with the text, and if you are willing to run Jupyter rather than import a library. Do not adopt it as a production dependency: the setup metadata is stale, the requirements are unpinned, and the distributions are duplicated, with jupyter, numpy, matplotlib, plotly, seaborn, scipy, statsmodels and tables all landing in your environment. Before you start, read requirements.txt, install it in a dedicated environment, and check which edition you actually want, since a third edition is online while this repository tracks the second.

Frequently asked questions

How do I run the ThinkStats2 notebooks?

The documentation points to Colab as the easiest route, with one link per chapter for the examples and one for the solutions. To run them locally, download the notebooks from GitHub or the repository Zip file, install the packages in requirements.txt, and open them in Jupyter.

Which Python version does ThinkStats2 need?

The Makefile sets PYTHON_VERSION = 3.10 and creates a conda environment with that version. The project was developed with Anaconda, a free Python distribution that includes the packages needed to run the code.

How are the tests for ThinkStats2 run?

The Makefile test target runs pytest with nbmake over the solution notebooks and the chapter notebooks, then runs thinkstats2_test.py from the code directory. The thinkplot_test script is commented out because it hangs on MacOS and Windows.

Can I install ThinkStats2 as a Python package?

The setup metadata is out of date: it imports distutils.core, which was removed from the standard library in Python 3.12, hardcodes version 2.0.0 while the published tag is v2.2.1, and points its url at the ThinkBayes2 repository. The documented route is to install requirements.txt and run the notebooks from a checkout.

What licence applies to the Think Stats book and to its code?

The repository code is under GPL-3.0, while the book is under a Creative Commons licence that allows copying, distribution and modification with attribution and without commercial use. The two sets of terms differ, so check which one covers the file you want to reuse.

Official sources

  1. AllenDowney/ThinkStats2 on GitHub
  2. License: GPL-3.0
  3. Project website
  4. README
  5. Releases
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/allendowney-thinkstats2.svg)](https://hysenlabs.com/projects/allendowney-thinkstats2)

Was this useful?