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

Cenpy Library cannot fetch Pittsburgh, PA data

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

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'])

这将 return 一个错误:

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

type of place to focus on, Incorporated Place, County Subdivision, or Census Designated Place.

查看 this colab 中的演示。