jtleider / censusdata

Download data from Census API
MIT License
139 stars 29 forks source link

Issue with TableID S0101 #30

Closed sowdm closed 3 years ago

sowdm commented 3 years ago

I have version 1.13 of CensusData. When I try to run censusdata.censustable("acs1", 2016, "S0101") for subject table S0101 (https://data.census.gov/cedsci/table?q=sex%20by%20age&g=0500000US51059&y=2016&tid=ACSST1Y2016.S0101), I get the following error:

Traceback (most recent call last): File "", line 1, in File "/home/matt/Projects/NAACP/.venv/lib/python3.8/site-packages/censusdata/variable_info.py", line 110, in censustable raise ValueError(u'Table not found!') ValueError: Table not found!

It seems to break the assumption in line 105 that the table ID will be the variable up to the last underscore (''.join(k.split('')[:-1]) == table).

I tried to use table "S0101_C01" instead based on looking at your acs1_2016_subject_variables.json file since using that as the table should and did work

tableInfo = censusdata.censustable("acs1", 2016, "S0101_C01") fullTable = censusdata.download("acs1", 2016, censusdata.censusgeo([('state', '51'), ('county', '059')]), list(tableInfo.keys()))

This gave me the error:

Traceback (most recent call last): File "", line 1, in File "/home/matt/Projects/NAACP/.venv/lib/python3.8/site-packages/censusdata/download.py", line 116, in download data.update(_download(src + tabletype, year, params, endpt=endpt)) File "/home/matt/Projects/NAACP/.venv/lib/python3.8/site-packages/censusdata/download.py", line 38, in _download raise ValueError('Unexpected response (URL: {0.url}): {0.text} '.format(r)) ValueError: Unexpected response (URL: https://api.census.gov/data/2016/acs/acs1?get=NAME,S0101_C01_001E,S0101_C01_002E,S0101_C01_003E,S0101_C01_004E,S0101_C01_005E,S0101_C01_006E,S0101_C01_007E,S0101_C01_008E,S0101_C01_009E,S0101_C01_010E,S0101_C01_011E,S0101_C01_012E,S0101_C01_013E,S0101_C01_014E,S0101_C01_015E,S0101_C01_016E,S0101_C01_017E,S0101_C01_018E,S0101_C01_019E,S0101_C01_020E,S0101_C01_021E,S0101_C01_022E,S0101_C01_023E,S0101_C01_024E,S0101_C01_025E,S0101_C01_026E,S0101_C01_027E,S0101_C01_028E,S0101_C01_029E,S0101_C01_030E,S0101_C01_031E,S0101_C01_032E,S0101_C01_033E,S0101_C01_034E,S0101_C01_035E,S0101_C01_036E&for=county:059&in=state:51): error: error: unknown variable 'S0101_C01_001E'

jtleider commented 3 years ago

It sounds like the available variables must have been changed by the Census. I will look into this and update the package accordingly. In the meantime, you can find documentation on the tables directly on the Census website at https://www.census.gov/data/developers/data-sets/acs-1year.html.

jtleider commented 3 years ago

Pulled in updated variable information from Census. This code now works: tableInfo = censusdata.censustable("acs1", 2016, "S0101_C01") fullTable = censusdata.download("acs1", 2016, censusdata.censusgeo([('state', '51'), ('county', '059')]), list(tableInfo.keys()), tabletype='subject')