各州的國會選區
賓州一家以家庭為主的倡議非營利組織想要找出各國會選區的平均家庭規模,好針對家庭較大的選區聯絡其民意代表。這題需要你知道賓州的 GEOID(ANSI Code)。如果不記得前面練習提過的代碼,請使用[密蘇里人口普查資料中心的 Geographic Codes Lookup](https://mcdc.missouri.edu/applications/geocodes/) 查詢。
requests 與 pandas(以 pd 匯入)套件已經匯入。base_url 已定義,predicates 字典也已包含要請求的變數清單。
本練習屬於課程
使用 Python 分析美國 Census 資料
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Build dictionary of predicates and execute the request
predicates[____] = ____
predicates[____] = ____
r = requests.get(base_url, params=predicates)
# Construct the DataFrame
col_names = ["name", "avg_family_size", "state", "cd"]
cd = pd.DataFrame(columns=col_names, data=r.json()[1:])