Skip to main content

Chapter 1 Exploratory Data Analysis

The thesis of this book is we can use data to answer questions, resolve debates, and make better decisions.
This chapter introduces the steps weโ€™ll use to do that: loading and validating data, exploring, and choosing statistics that measure what we are interested in. As an example, weโ€™ll use data from the National Survey of Family Growth (NSFG) to answer a question I heard when my wife and I were expecting our first child: do first babies tend to arrive late?
Listing 1.0.1. Python Code
from os.path import basename, exists


def download(url):
    filename = basename(url)
    if not exists(filename):
        from urllib.request import urlretrieve

        local, _ = urlretrieve(url, filename)
        print("Downloaded " + local)


download("https://github.com/AllenDowney/ThinkStats/raw/v3/nb/thinkstats.py")
Listing 1.0.2. Python Code
try:
    import empiricaldist
except ImportError:
    %pip install empiricaldist
Listing 1.0.3. Python Code
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

from IPython.display import HTML
from thinkstats import decorate