人口普查地理

使用 Python 分析美国人口普查数据

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 分析美国人口普查数据

请求特定地理单元

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 分析美国人口普查数据

密苏里人口普查数据中心网页截图,显示各州及其地理代码

1 https://census.missouri.edu/geocodes/
使用 Python 分析美国人口普查数据

地理实体

法律/行政类

  • State
  • County
  • Congressional Districts
  • School Districts
  • 等等

统计类

  • Block
  • (Census) Tract
  • 大都市/小都市统计区
  • 邮编统计区(ZCTA)
  • 等等
1 https://www.census.gov/geo/education/legstat_geo.html
使用 Python 分析美国人口普查数据

一个层级图,显示人口普查地理之间的包含关系。

使用 Python 分析美国人口普查数据

"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 分析美国人口普查数据

地方(Places)

  • "为向一群体提供政府职能而设立的称为设市地(incorporated place)。设市地通常是市、镇、村或自治区划分,但也可有其他法律描述。"
  • "普查指定地(CDP)是设市地的统计对应物,划定用于提供具名但未依法设市的人口聚居地的数据。"

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

使用 Python 分析美国人口普查数据
地理级别 地理层级
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 分析美国人口普查数据

部分地理单元(Part)

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"]]
使用 Python 分析美国人口普查数据

Ayo berlatih!

使用 Python 分析美国人口普查数据

Preparing Video For Download...