jvns /pandas-cookbook

Recipes for using Python's pandas library

★ 7,121⑂ 2,344👁 293⑃ 43● 45▤ 0
Jupyter NotebookCreated 2013-12-22
7,121
stars
+0+3+2
2,344
forks
293
watchers
43
prs
45
issues
0
releases
–
discussions

README

Pandas cookbook
===============

Try it in your browser with Jupyter Lite: 

pandas is a Python library for doing
data analysis. It's really fast and lets you do exploratory work
incredibly quickly.

The goal of this cookbook is to give you some concrete examples for
getting started with pandas. The docs
are really comprehensive. However, I've often had people
tell me that they have some trouble getting started, so these are
examples with real-world data, and all the bugs and weirdness
that entails.

It uses 3 datasets:

 311 calls in New York
 How many people were on Montréal's bike paths in 2012
 Montreal's weather for 2012, hourly

It comes with batteries (data) included, so you can try out all the
examples right away.

Table of Contents
=================


 A quick tour of the Jupyter Notebook
   Shows off Jupyter's awesome tab completion and magic functions.
 Chapter 1: Reading from a CSV
   Reading your data into pandas is pretty much the easiest thing. Even when the encoding is wrong!
 Chapter 2: Selecting data & finding the most common complaint type
  It's not totally obvious how to select data from a pandas dataframe. Here I explain the basics (how to take slices and get columns)
 Chapter 3: Which borough has the most noise complaints? (or, more selecting data)
  Here we get into serious slicing and dicing and learn how to filter dataframes in complicated ways, really fast.
 Chapter 4: Find out on which weekday people bike the most with groupby and aggregate
   The groupby/aggregate is seriously my favorite thing about pandas and I use it all the time. You should probably read this.
 Chapter 5: Combining dataframes and scraping Canadian weather data
  Here you get to find out if it's cold in Montreal in the winter (spoiler: yes). Web scraping with pandas is fun!
 Chapter 6: String operations! Which month was the snowiest?
   Strings with pandas are great. It has all these vectorized string operations and they're the best. We will turn a bunch of strings containing "Snow" into vectors of numbers in a trice.
 Chapter 7: Cleaning up messy data
   Cleaning up messy data is never a joy, but with pandas it's easier <3
 Chapter 8: Parsing Unix timestamps
   This is basically a quick trick that took me 2 days to figure out.
 Chapter 9 - Loading data from SQL databases
   How to load data from an SQL database into Pandas, with examples using SQLite3, PostgreSQL, and MySQL.

How to use this cookbook
========================

You can try it out instantly online using Jupyter Lite, which will run Python with WebAssembly in your browser.

To install it locally, you'll need Jupyter notebook and pandas on your computer.

You can get these using pip (you may want to do this inside a virtual environment to avoid conflicting with your other libraries).

bash
 Get the repository
git clone https://github.com/jvns/pandas-cookbook.git
cd pandas-cookbook

 Set up a virtual environment
python3 -m venv venv
source venv/bin/activate

 Install dependencies
pip

Snapshot: 2026-11-04T14:00:00Z · Data license Apache-2.0 · JSON