Census Geography

Analyzing US Census Data in Python

Lee Hachadoorian

Asst. Professor of Instruction, Temple University

Request All Geographies

import requests

HOST = "https://api.census.gov/data"
year = "2010"
dataset = "dec/sf1"
base_url = "/".join([HOST, year, dataset])

predicates = {}
predicates["get"] = "NAME,P001001"

predicates["for"] = "state:*"
r = requests.get(base_url, params=predicates)
Analyzing US Census Data in Python

Request Specific Geographies

import requests

HOST = "https://api.census.gov/data"
year = "2010"
dataset = "dec/sf1"
base_url = "/".join([HOST, year, dataset])

predicates = {}
predicates["get"] = "NAME,P001001"

predicates["for"] = "state:42"
r = requests.get(base_url, params=predicates)
Analyzing US Census Data in Python

A screenshot of the Missouri Census Data Center webpage showing states and their Geographic Identifiers

1 https://census.missouri.edu/geocodes/
Analyzing US Census Data in Python

Geographic Entities

Legal/Administrative

  • State
  • County
  • Congressional Districts
  • School Districts
  • etc.

Statistical

  • Block
  • (Census) Tract
  • Metropolitan/Micropolitan Statistical Area
  • ZIP Code Tabulation Area
  • etc.
1 https://www.census.gov/geo/education/legstat_geo.html
Analyzing US Census Data in Python

A hierarchy diagram showing Census geographies connected by lines indicating which geographies are contained by other, larger geographies.

Analyzing US Census Data in Python

The "in" Predicate

Request all counties in specific states:

predicates["for"] = "county:*"
predicates["in"] = "state:33,50"

Request specific counties in one state:

predicates["for"] = "county:001,003"
predicates["in"] = "state:33"
r = requests.get(base_url, params=predicates)
Analyzing US Census Data in Python

Places

  • "An incorporated place is established to provide governmental functions for a concentration of people…. An incorporated place usually is a city, town, village, or borough, but can have other legal descriptions."
  • "Census Designated Places (CDPs) are the statistical counterparts of incorporated places, and are delineated to provide data for settled concentrations of population that are identifiable by name but are not legally incorporated under the laws of the state in which they are located."

Source: https://www.census.gov/geo/reference/gtc/gtc_place.html

Analyzing US Census Data in Python
Geography Level Geography Hierarchy
40 state
50 state› county
60 state› county› county subdivision
101 state› county› tract› block
140 state› county› tract
150 state› county› tract› block group
160 state› place

https://api.census.gov/data/2010/dec/sf1/geography.html

Analyzing US Census Data in Python

Part Geographies

state› congressional district› county (or part)

predicates = {}
predicates["get"] = "NAME,P001001"

predicates["for"] = "county (or part):*"
predicates["in"] = "state:42;congressional district:02"
r = requests.get(base_url, params=predicates) print(r.text)
[["NAME","P001001","state","congressional district","county"],
["Montgomery County (part)","36793","42","02","091"],
["Philadelphia County (part)","593484","42","02","101"]]
Analyzing US Census Data in Python

Let's practice!

Analyzing US Census Data in Python

Preparing Video For Download...