我可以从普查API获取地名和变量标签吗?

2024-06-24 12:34:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用python中的人口普查包装器将数据从人口普查API拉到Pandas。有人知道通过API获取变量标签和地名的方法吗?我用两个名称和每个域和变量的变量名的字典进行设置,然后在查询后将它们映射到数据帧。但这似乎是多余的,我应该能够从查询中获得这些信息。有什么想法吗

目前来看,人口统计数据是这样的(实际上有25个以上的变量,大约25个区域):

census_variables = 'B02001_001E,B02001_002E,B02001_003E'
variable_labels = {'B02001_001E':'Estimate!!Total','B02001_002E':'Estimate!!Total!!White alone', 'B02001_003E':'Estimate!!Total!!Black or African American alone'} 
# variable:label

tracts = ['170100', '170200']
tract_named={'170100':'REVERE', '170200':'REVERE'}
# tract:town

and then a loop to do the queries and add them to the dataframe.
for t in tracts:
    result = c.acs5.get(('NAME',census_variables), geo={'for': 'tract:{}'.format(t),
                       'in': 'state:25 county:025'},year=2018)
    df=df.append(result,ignore_index=True)

Tags: andto数据apivariablesvariabletotal人口普查