March 5-6, 2020 - NICAR, New Orleans

Tom Meagher / @ultracasual
Elaine Wong / @elthenerd
Winny de Jong / @winnydejong
Adam Hooper / @adamhooper
Jacob Sanders / @thejqs
Eric Sagara / @esagara

Why should you code?

Cover more ground, faster

Helps document reporting

Makes analysis replicable


We won't learn everything

The Command Line

Git or Github

pip or virtualenvs


News apps

Journalism > "Development"

This will not be nuanced, idiomatic Python.

Some programmers may be saddened by this code.

But you know what? If it works, and it works on deadline, that's what matters for us today.

The goal

To start thinking about
how to break problems down
into the smallest tasks
that can be programmed.

If you know Excel

You can learn to program.

  • "AZ Arizona" is a string.
  • "A2" is a variable.
  • "=left()" is a function.
  • A2 and 2 are function arguments.

Why Python?

Easy to learn.


Mature and well-documented.

Strong PythonJournos community of support.

Prep your workspace

To set up your machine, you'll need to have Python 3, pip, virtualenv and virtualenvwrapper installed.

#create and activate a sandbox to work in
mkvirtualenv pycar18

#clone or download the code repo from Github
git clone

#install the dependencies: 
#jupyter, requests, beautifulsoup4, lxml, pandas
pip3 install -r requirements.txt

#launch the interactive Jupyter notebook in your browser
jupyter notebook


Strings are ordered sequences of characters wrapped in quotes.

var1 = "This class is at NICAR in New Orleans."
var2 = "&You!_123 Four"

Follow along at home here.
If you want to cheat, the answers are here.

Integers and Floats

Numbers that you can do math on.

Integers are whole numbers.
Floats are decimals.


An ordered collection of objects, wrapped in brackets.

my_list = [1, 2, "Jax"]


A collection of named keys and their associated values, wrapped in curly braces.

my_dict = {'Fruit': 'Orange', 'Weight': 10}


Logic that can trigger other operations,
similar to Excel's if function.

In Excel:

In Python:

score = 1
if score > 2:


Keep learning

"Data Wrangling with Python"

"Web Scraping With Python"

PythonJournos listserv

Excellent post on ethics of scraping

More resources for learning Python


Github, StackOverflow, Google


Clone the source code

Even more questions? Email Tom or ping me on Twitter