人口普查地理

使用 Python 分析美國 Census 資料

Lee Hachadoorian

Asst. Professor of Instruction, Temple University

請求所有地理層級

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)
使用 Python 分析美國 Census 資料

請求特定地理層級

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)
使用 Python 分析美國 Census 資料

密蘇里人口普查資料中心網頁截圖,顯示各州及其地理識別碼

1 https://census.missouri.edu/geocodes/
使用 Python 分析美國 Census 資料

地理實體

法律/行政

  • State(州)
  • County(郡)
  • Congressional Districts(國會選區)
  • School Districts(學區)
  • 等等

統計

  • Block(街區)
  • (Census)Tract(普查分區)
  • Metropolitan/Micropolitan Statistical Area(都會/次都會統計區)
  • ZIP Code Tabulation Area(ZIP 編碼彙編區)
  • 等等
1 https://www.census.gov/geo/education/legstat_geo.html
使用 Python 分析美國 Census 資料

一張階層圖,顯示人口普查地理層級,以連線表示較小地理包含於較大地理之中。

使用 Python 分析美國 Census 資料

「in」述詞

在特定州請求所有郡:

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

在單一州請求特定郡:

predicates["for"] = "county:001,003"
predicates["in"] = "state:33"
r = requests.get(base_url, params=predicates)
使用 Python 分析美國 Census 資料

Places(聚落)

  • incorporated place(建制聚落)是為一群人口提供政府功能而設立的……建制聚落通常是 city、town、village 或 borough,也可能有其他法律稱謂。」
  • Census Designated Places (CDPs)(人口普查指定地區)是建制聚落的統計對應,用於提供對具名、已聚居但未依其所在州法律正式建制之地區的人口資料。」

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

使用 Python 分析美國 Census 資料
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

使用 Python 分析美國 Census 資料

部分地理區

state› congressional district› county(或部分)

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"]]
使用 Python 分析美國 Census 資料

一起來練習吧!

使用 Python 分析美國 Census 資料

Preparing Video For Download...