Cenpy 库无法获取宾夕法尼亚州匹兹堡的数据

问题描述

我正在开展一个项目,试图分析来自美国宾夕法尼亚州匹兹堡的大量 ACS 人口普查数据。我可以轻松地转到 data.census.gov 获取我正在寻找的 138 个人口普查区所需的数据,但这根本没有效率。所以我下载了适用于纽约市 ACS 数据的 cenpy 库。以下是纽约市的示例:

NYC_income = products.ACS(2019).from_place('New York City,NY',level = 'tract',variables = ['B19013_001E'])

这很好用,并且会给我一个带有我传入的 ACS 变量的地理数据框。我已经在匹兹堡尝试过这个,但它不起作用,错误也不是很有帮助:

pgh_Test = products.ACS(2019).from_place('Pittsburgh,PA',level='tract',variables = ['B01001A_001E'])

这将返回一个错误

KeyError: 'Response from API is malformed. You may have submitted too many queries,formatted the request incorrectly,or experienced significant network connectivity 
issues. Check to make sure that your inputs,like placenames,are spelled correctly,and that your geographies match the level at which you intend to query. The original 
error from the Census is:\\n(API ERROR 400:Failed to execute query.([]))'

我还尝试了其他拼写 Pittsburgh 的变体,例如 Pittsburgh CityPittsburgh cityPittsburg,并且还尝试拼写状态而不是使用首字母缩略词。

最终,我很好奇是否有人遇到过这个问题以及如何解决它,以便我可以通过 cenpy 访问匹兹堡 ACS 数据,而不是通过 data.census.gov 选择每个单独的人口普查区。

先谢谢你!

解决方法

使用 'County Subdivision' 作为 place_type。似乎有助于正确解析该地点:

products.ACS(2019).from_place('Pittsburgh,PA',place_type='County Subdivision',level='tract',variables = ['B01001A_001E'])

输出:

Matched: Pittsburgh,PA to Pittsburgh city within layer County Subdivisions
GEOID   geometry    B01001A_001E    state   county  tract
0   42003270300 POLYGON ((-8910344.550 4935795.800,-8910341.7...   1154.0  42  003 270300
1   42003980600 POLYGON ((-8909715.600 4933176.800,-8909606.6...   13.0    42  003 980600
2   42003051100 POLYGON ((-8903296.360 4930484.040,-8903251.9...   0.0 42  003 051100
3   42003050900 POLYGON ((-8903766.910 4931335.660,-8903642.5...   40.0    42  003 050900
4   42003562000 POLYGON ((-8901104.700 4930705.200,-8901104.1...   1826.0  42  003 562000
... ... ... ... ... ... ...
84  42003980500 POLYGON ((-8899981.160 4929217.570,-8899977.7...   16.0    42  003 980500
85  42003140200 POLYGON ((-8898569.740 4931230.040,-8898532.8...   1932.0  42  003 140200
86  42003111300 POLYGON ((-8898077.150 4934571.530,-8898053.1...   1499.0  42  003 111300
87  42003111500 POLYGON ((-8898240.670 4932660.630,-8898229.9...   942.0   42  003 111500
88  42003120700 POLYGON ((-8895502.550 4932516.230,-8895493.0...   17.0    42  003 120700
89 rows × 6 columns

此参数的其他值是 'Incorporated Place''Census Designated Place'。来自the documentation

place_type : str

要关注的地点类型,注册地、县分区或人口普查指定地点。

查看 this colab 中的演示。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...