Exploring a Group of Variables
There are thousands of different variables avaialble via the US Census API. One way to navigate through them is to look through a hierarchy of web pages starting with a year, like 2020, on a page like https://api.census.gov/data/2020.html.
From here we can navigate down to a particular data source, by following the link in the Group List column of the first row, which is for the dataset acs/acs5. This takes us to https://api.census.gov/data/2020/acs/acs5/groups.html.
From there, we can choose the group named B03002, which takes us to https://api.census.gov/data/2020/acs/acs5/groups/B03002.html, where we can see all the variables in the group.
Some of these variables are estimates, and some of them are annotations. Normally, we are interested in the estimates.
Every variable has a label, which is a string of components seperated by !!. For example, B03002_007E has the label, “Estimate!!Total:!!Not Hispanic or Latino:!!Native Hawaiian and Other Pacific Islander alone”. The !! seperators imply a tree among the variables, from the root all the way down to leaves. Internal nodes in the tree represent variables that are aggregates of those lower than them in the tree. For example, B03002_002E is the size of the population that is not Hispanic or Latino, regardless of race. It is the sum of B03002_003E, B03002_004E, B03002_005E, B03002_006E, B03002_007E, B03002_008E, and B03002_009E, which count people of different races who are not Hispanic or Latino. All of these are leaves of the tree, except B03002_009E, which is further subdivided into B03002_010E and B03002_011E.
All of this can get really confusing when you look at it in the tabular form on the web page. In order to make it less confusing, the censusdis package includes code to fetch and present the variable hierarchy in a more understandable way. That’s what the remainder of this notebook is about.
Import and Configuration
[1]:
# So we can run from within the censusdis project and find the packages we need.
import os
import sys
sys.path.append(
os.path.join(os.path.abspath(os.path.join(os.path.curdir, os.path.pardir)))
)
[2]:
import censusdis.data as ced
import censusdis.geography as cgeo
from censusdis.states import STATE_NJ
[3]:
YEAR = 2020
DATASET = "acs/acs5"
GROUP = "B03002"
Programmatic Access to a Group Variable Tree
We can get the whole collection of variables in tree form and print it. This format makes it easier to see the relationships we saw in the table at https://api.census.gov/data/2020/acs/acs5/groups/B03002.html.
We can see clearly where variables exist at internal nodes of the tree and where they exist at the leaves. Not all internal nodes have variables but all leaves do.
[4]:
tree = ced.variables.group_tree(DATASET, YEAR, GROUP)
print(tree)
+ Estimate
+ Total: (B03002_001E)
+ Not Hispanic or Latino: (B03002_002E)
+ White alone (B03002_003E)
+ Black or African American alone (B03002_004E)
+ American Indian and Alaska Native alone (B03002_005E)
+ Asian alone (B03002_006E)
+ Native Hawaiian and Other Pacific Islander alone (B03002_007E)
+ Some other race alone (B03002_008E)
+ Two or more races: (B03002_009E)
+ Two races including Some other race (B03002_010E)
+ Two races excluding Some other race, and three or more races (B03002_011E)
+ Hispanic or Latino: (B03002_012E)
+ White alone (B03002_013E)
+ Black or African American alone (B03002_014E)
+ American Indian and Alaska Native alone (B03002_015E)
+ Asian alone (B03002_016E)
+ Native Hawaiian and Other Pacific Islander alone (B03002_017E)
+ Some other race alone (B03002_018E)
+ Two or more races: (B03002_019E)
+ Two races including Some other race (B03002_020E)
+ Two races excluding Some other race, and three or more races (B03002_021E)
+ Annotation of Estimate
+ Total: (B03002_001EA)
+ Not Hispanic or Latino: (B03002_002EA)
+ White alone (B03002_003EA)
+ Black or African American alone (B03002_004EA)
+ American Indian and Alaska Native alone (B03002_005EA)
+ Asian alone (B03002_006EA)
+ Native Hawaiian and Other Pacific Islander alone (B03002_007EA)
+ Some other race alone (B03002_008EA)
+ Two or more races: (B03002_009EA)
+ Two races including Some other race (B03002_010EA)
+ Two races excluding Some other race, and three or more races (B03002_011EA)
+ Hispanic or Latino: (B03002_012EA)
+ White alone (B03002_013EA)
+ Black or African American alone (B03002_014EA)
+ American Indian and Alaska Native alone (B03002_015EA)
+ Asian alone (B03002_016EA)
+ Native Hawaiian and Other Pacific Islander alone (B03002_017EA)
+ Some other race alone (B03002_018EA)
+ Two or more races: (B03002_019EA)
+ Two races including Some other race (B03002_020EA)
+ Two races excluding Some other race, and three or more races (B03002_021EA)
+ Margin of Error
+ Total: (B03002_001M)
+ Not Hispanic or Latino: (B03002_002M)
+ White alone (B03002_003M)
+ Black or African American alone (B03002_004M)
+ American Indian and Alaska Native alone (B03002_005M)
+ Asian alone (B03002_006M)
+ Native Hawaiian and Other Pacific Islander alone (B03002_007M)
+ Some other race alone (B03002_008M)
+ Two or more races: (B03002_009M)
+ Two races including Some other race (B03002_010M)
+ Two races excluding Some other race, and three or more races (B03002_011M)
+ Hispanic or Latino: (B03002_012M)
+ White alone (B03002_013M)
+ Black or African American alone (B03002_014M)
+ American Indian and Alaska Native alone (B03002_015M)
+ Asian alone (B03002_016M)
+ Native Hawaiian and Other Pacific Islander alone (B03002_017M)
+ Some other race alone (B03002_018M)
+ Two or more races: (B03002_019M)
+ Two races including Some other race (B03002_020M)
+ Two races excluding Some other race, and three or more races (B03002_021M)
+ Annotation of Margin of Error
+ Total: (B03002_001MA)
+ Not Hispanic or Latino: (B03002_002MA)
+ White alone (B03002_003MA)
+ Black or African American alone (B03002_004MA)
+ American Indian and Alaska Native alone (B03002_005MA)
+ Asian alone (B03002_006MA)
+ Native Hawaiian and Other Pacific Islander alone (B03002_007MA)
+ Some other race alone (B03002_008MA)
+ Two or more races: (B03002_009MA)
+ Two races including Some other race (B03002_010MA)
+ Two races excluding Some other race, and three or more races (B03002_011MA)
+ Hispanic or Latino: (B03002_012MA)
+ White alone (B03002_013MA)
+ Black or African American alone (B03002_014MA)
+ American Indian and Alaska Native alone (B03002_015MA)
+ Asian alone (B03002_016MA)
+ Native Hawaiian and Other Pacific Islander alone (B03002_017MA)
+ Some other race alone (B03002_018MA)
+ Two or more races: (B03002_019MA)
+ Two races including Some other race (B03002_020MA)
+ Two races excluding Some other race, and three or more races (B03002_021MA)
Accessing a Sub-Tree
Most of the time we are only interested in variables that are estimates, so we can look down in that part of the tree alone.
[5]:
print(tree["Estimate"])
+ Total: (B03002_001E)
+ Not Hispanic or Latino: (B03002_002E)
+ White alone (B03002_003E)
+ Black or African American alone (B03002_004E)
+ American Indian and Alaska Native alone (B03002_005E)
+ Asian alone (B03002_006E)
+ Native Hawaiian and Other Pacific Islander alone (B03002_007E)
+ Some other race alone (B03002_008E)
+ Two or more races: (B03002_009E)
+ Two races including Some other race (B03002_010E)
+ Two races excluding Some other race, and three or more races (B03002_011E)
+ Hispanic or Latino: (B03002_012E)
+ White alone (B03002_013E)
+ Black or African American alone (B03002_014E)
+ American Indian and Alaska Native alone (B03002_015E)
+ Asian alone (B03002_016E)
+ Native Hawaiian and Other Pacific Islander alone (B03002_017E)
+ Some other race alone (B03002_018E)
+ Two or more races: (B03002_019E)
+ Two races including Some other race (B03002_020E)
+ Two races excluding Some other race, and three or more races (B03002_021E)
Leaves
In many cases, we are really just interested in the leaves, because the internal nodes of the tree contain variables that are aggregate sums of the subtrees below them.
[6]:
leaves = ced.variables.group_leaves(DATASET, YEAR, GROUP)
leaves
[6]:
['B03002_003E',
'B03002_004E',
'B03002_005E',
'B03002_006E',
'B03002_007E',
'B03002_008E',
'B03002_010E',
'B03002_011E',
'B03002_013E',
'B03002_014E',
'B03002_015E',
'B03002_016E',
'B03002_017E',
'B03002_018E',
'B03002_020E',
'B03002_021E']
Notice that the set of leaves we got does not include those for annotations. If we really want to see those too, we can add an optional argument.
[7]:
all_leaves = ced.variables.group_leaves(DATASET, YEAR, GROUP, skip_annotations=False)
all_leaves
[7]:
['B03002_003E',
'B03002_003EA',
'B03002_003M',
'B03002_003MA',
'B03002_004E',
'B03002_004EA',
'B03002_004M',
'B03002_004MA',
'B03002_005E',
'B03002_005EA',
'B03002_005M',
'B03002_005MA',
'B03002_006E',
'B03002_006EA',
'B03002_006M',
'B03002_006MA',
'B03002_007E',
'B03002_007EA',
'B03002_007M',
'B03002_007MA',
'B03002_008E',
'B03002_008EA',
'B03002_008M',
'B03002_008MA',
'B03002_010E',
'B03002_010EA',
'B03002_010M',
'B03002_010MA',
'B03002_011E',
'B03002_011EA',
'B03002_011M',
'B03002_011MA',
'B03002_013E',
'B03002_013EA',
'B03002_013M',
'B03002_013MA',
'B03002_014E',
'B03002_014EA',
'B03002_014M',
'B03002_014MA',
'B03002_015E',
'B03002_015EA',
'B03002_015M',
'B03002_015MA',
'B03002_016E',
'B03002_016EA',
'B03002_016M',
'B03002_016MA',
'B03002_017E',
'B03002_017EA',
'B03002_017M',
'B03002_017MA',
'B03002_018E',
'B03002_018EA',
'B03002_018M',
'B03002_018MA',
'B03002_020E',
'B03002_020EA',
'B03002_020M',
'B03002_020MA',
'B03002_021E',
'B03002_021EA',
'B03002_021M',
'B03002_021MA']
Programmatic Access to Geographic Hierarchies
It’s great to know the variables that are available, but in order to make full use of the US Census API and the censusdis API around it, we have to know something about the geography hierarchies that are avaialble for each dataset in each year it is available. These are available on web pages like https://api.census.gov/data/2020/acs/acs5/geography.html, which contains a table of the geographies supported by the ACS5 dataset we have been looking at for the year 2020.
But again, we’d prefer to have access to this information in a pythonic way. The most common way to get this is by calling censusdis.geography.geo_path_py_specs as shown below. This gives us the available hierarchies using Python-friendly snake-case names that we can use to download data.
Each item in the dictionary has a key that represents the geography hierarchy and a value that is the list of the components of the hierachy in snake-case as it can be passed as an argument to censusdis.data.download_detail.
[8]:
cgeo.geo_path_snake_specs(DATASET, YEAR)
[8]:
{'010': ['us'],
'020': ['region'],
'030': ['division'],
'040': ['state'],
'050': ['state', 'county'],
'060': ['state', 'county', 'county_subdivision'],
'067': ['state', 'county', 'county_subdivision', 'subminor_civil_division'],
'070': ['state', 'county', 'county_subdivision', 'place_remainder_or_part'],
'140': ['state', 'county', 'tract'],
'150': ['state', 'county', 'tract', 'block_group'],
'155': ['state', 'place', 'county_or_part'],
'160': ['state', 'place'],
'170': ['state', 'consolidated_city'],
'172': ['state', 'consolidated_city', 'place_or_part'],
'230': ['state', 'alaska_native_regional_corporation'],
'250': ['american_indian_area_alaska_native_area_hawaiian_home_land'],
'251': ['american_indian_area_alaska_native_area_hawaiian_home_land',
'tribal_subdivision_remainder'],
'252': ['american_indian_area_alaska_native_area_reservation_or_statistical_entity_only'],
'254': ['american_indian_area_off_reservation_trust_land_only_hawaiian_home_land'],
'256': ['american_indian_area_alaska_native_area_hawaiian_home_land',
'tribal_census_tract'],
'258': ['american_indian_area_alaska_native_area_hawaiian_home_land',
'tribal_census_tract',
'tribal_block_group'],
'260': ['american_indian_area_alaska_native_area_hawaiian_home_land',
'state_or_part'],
'269': ['american_indian_area_alaska_native_area_hawaiian_home_land',
'state_or_part',
'place_remainder_or_part'],
'270': ['american_indian_area_alaska_native_area_hawaiian_home_land',
'state_or_part',
'county_or_part'],
'280': ['state',
'american_indian_area_alaska_native_area_hawaiian_home_land_or_part'],
'283': ['state',
'american_indian_area_alaska_native_area_reservation_or_statistical_entity_only_or_part'],
'286': ['state',
'american_indian_area_off_reservation_trust_land_only_hawaiian_home_land_or_part'],
'290': ['american_indian_area_alaska_native_area_hawaiian_home_land',
'tribal_subdivision_remainder',
'state_or_part'],
'291': ['american_indian_area_reservation_only',
'tribal_census_tract_or_part'],
'292': ['american_indian_area_off_reservation_trust_land_only_hawaiian_home_land',
'tribal_census_tract_or_part'],
'293': ['american_indian_area_reservation_only',
'tribal_census_tract_or_part',
'tribal_block_group_or_part'],
'294': ['american_indian_area_off_reservation_trust_land_only_hawaiian_home_land',
'tribal_census_tract_or_part',
'tribal_block_group_or_part'],
'310': ['metropolitan_statistical_area_micropolitan_statistical_area'],
'311': ['metropolitan_statistical_area_micropolitan_statistical_area',
'state_or_part'],
'312': ['metropolitan_statistical_area_micropolitan_statistical_area',
'state_or_part',
'principal_city_or_part'],
'313': ['metropolitan_statistical_area_micropolitan_statistical_area',
'state_or_part',
'county'],
'314': ['metropolitan_statistical_area_micropolitan_statistical_area',
'metropolitan_division'],
'315': ['metropolitan_statistical_area_micropolitan_statistical_area',
'metropolitan_division',
'state_or_part'],
'316': ['metropolitan_statistical_area_micropolitan_statistical_area',
'metropolitan_division',
'state_or_part',
'county'],
'320': ['state',
'metropolitan_statistical_area_micropolitan_statistical_area_or_part'],
'321': ['state',
'metropolitan_statistical_area_micropolitan_statistical_area_or_part',
'principal_city_or_part'],
'322': ['state',
'metropolitan_statistical_area_micropolitan_statistical_area_or_part',
'county'],
'323': ['state',
'metropolitan_statistical_area_micropolitan_statistical_area_or_part',
'metropolitan_division_or_part'],
'324': ['state',
'metropolitan_statistical_area_micropolitan_statistical_area_or_part',
'metropolitan_division_or_part',
'county'],
'330': ['combined_statistical_area'],
'331': ['combined_statistical_area', 'state_or_part'],
'332': ['combined_statistical_area',
'metropolitan_statistical_area_micropolitan_statistical_area'],
'333': ['combined_statistical_area',
'metropolitan_statistical_area_micropolitan_statistical_area',
'state_or_part'],
'335': ['combined_new_england_city_and_town_area'],
'336': ['combined_new_england_city_and_town_area', 'state_or_part'],
'337': ['combined_new_england_city_and_town_area',
'new_england_city_and_town_area'],
'338': ['combined_new_england_city_and_town_area',
'new_england_city_and_town_area',
'state_or_part'],
'340': ['state', 'combined_statistical_area_or_part'],
'341': ['state',
'combined_statistical_area_or_part',
'metropolitan_statistical_area_micropolitan_statistical_area_or_part'],
'345': ['state', 'combined_new_england_city_and_town_area_or_part'],
'346': ['state',
'combined_new_england_city_and_town_area_or_part',
'new_england_city_and_town_area_or_part'],
'350': ['new_england_city_and_town_area'],
'351': ['new_england_city_and_town_area', 'state_or_part'],
'352': ['new_england_city_and_town_area', 'state_or_part', 'principal_city'],
'353': ['new_england_city_and_town_area', 'state_or_part', 'county_or_part'],
'354': ['new_england_city_and_town_area',
'state_or_part',
'county_or_part',
'county_subdivision'],
'355': ['new_england_city_and_town_area', 'necta_division'],
'356': ['new_england_city_and_town_area', 'necta_division', 'state_or_part'],
'357': ['new_england_city_and_town_area',
'necta_division',
'state_or_part',
'county_or_part'],
'358': ['new_england_city_and_town_area',
'necta_division',
'state_or_part',
'county_or_part',
'county_subdivision'],
'360': ['state', 'new_england_city_and_town_area_or_part'],
'361': ['state', 'new_england_city_and_town_area_or_part', 'principal_city'],
'362': ['state', 'new_england_city_and_town_area_or_part', 'county_or_part'],
'363': ['state',
'new_england_city_and_town_area_or_part',
'county_or_part',
'county_subdivision'],
'364': ['state',
'new_england_city_and_town_area_or_part',
'necta_division_or_part'],
'365': ['state',
'new_england_city_and_town_area_or_part',
'necta_division_or_part',
'county_or_part'],
'366': ['state',
'new_england_city_and_town_area_or_part',
'necta_division_or_part',
'county_or_part',
'county_subdivision'],
'400': ['urban_area'],
'410': ['urban_area', 'state'],
'430': ['urban_area', 'state', 'county'],
'500': ['state', 'congressional_district'],
'510': ['state', 'congressional_district', 'county_or_part'],
'550': ['state',
'congressional_district',
'american_indian_area_alaska_native_area_hawaiian_home_land_or_part'],
'610': ['state', 'state_legislative_district_upper_chamber'],
'612': ['state',
'state_legislative_district_upper_chamber',
'county_or_part'],
'620': ['state', 'state_legislative_district_lower_chamber'],
'622': ['state',
'state_legislative_district_lower_chamber',
'county_or_part'],
'795': ['state', 'public_use_microdata_area'],
'860': ['zip_code_tabulation_area'],
'950': ['state', 'school_district_elementary'],
'960': ['state', 'school_district_secondary'],
'970': ['state', 'school_district_unified']}
Loading Data for Leaves
Once we know the variables we want, for example the leaves of group B03002 that we found above, and we select one of the geogpraphy types and fill in the particular values we want at each level, we can load data for them. In our case, we will use the one with the key '610', which represents the districts of the upper house of the legeslature of a state. The value associated with that key is a list of the keyword arguments we can pass to censusdis.data.download_detail to specifiy what
state and what district or disctricts within the state we want data for.
This call will load data for all the variablles at the leaves of the dataset we examined earlier for all state senate districts in NJ by using the keyword arguments state=STATE_NJ and state_legislative_district_upper_chamber="*".
[9]:
ced.download_detail(
DATASET, YEAR, leaves, state=STATE_NJ, state_legislative_district_upper_chamber="*"
)
[9]:
| STATE | STATE_LEGISLATIVE_DISTRICT_UPPER_CHAMBER | B03002_003E | B03002_004E | B03002_005E | B03002_006E | B03002_007E | B03002_008E | B03002_010E | B03002_011E | B03002_013E | B03002_014E | B03002_015E | B03002_016E | B03002_017E | B03002_018E | B03002_020E | B03002_021E | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 34 | 001 | 142196 | 21618 | 925 | 1963 | 6 | 371 | 487 | 4965 | 24460 | 1820 | 191 | 107 | 25 | 9969 | 2943 | 1306 |
| 1 | 34 | 002 | 107867 | 31770 | 547 | 17962 | 98 | 650 | 694 | 5588 | 16532 | 1398 | 694 | 128 | 16 | 18301 | 4893 | 1337 |
| 2 | 34 | 003 | 149678 | 33696 | 452 | 4264 | 24 | 237 | 358 | 4327 | 15417 | 931 | 179 | 22 | 22 | 6880 | 3862 | 590 |
| 3 | 34 | 004 | 148292 | 39088 | 216 | 7032 | 17 | 507 | 411 | 5723 | 8885 | 2564 | 287 | 41 | 0 | 5886 | 1202 | 1466 |
| 4 | 34 | 005 | 114996 | 42660 | 206 | 7225 | 18 | 690 | 142 | 3783 | 16543 | 2455 | 239 | 64 | 24 | 24589 | 5088 | 963 |
| 5 | 34 | 006 | 144747 | 22647 | 138 | 21829 | 63 | 1447 | 570 | 4509 | 11936 | 1762 | 92 | 40 | 71 | 9901 | 2583 | 1188 |
| 6 | 34 | 007 | 134612 | 47217 | 52 | 12108 | 50 | 871 | 561 | 7288 | 9159 | 1511 | 332 | 207 | 4 | 4596 | 2102 | 948 |
| 7 | 34 | 008 | 160610 | 22823 | 35 | 7878 | 113 | 388 | 561 | 6264 | 8291 | 1528 | 170 | 49 | 134 | 4174 | 2510 | 984 |
| 8 | 34 | 009 | 194162 | 7586 | 117 | 5480 | 46 | 418 | 196 | 4949 | 11273 | 928 | 12 | 64 | 0 | 3328 | 1989 | 183 |
| 9 | 34 | 010 | 188982 | 7378 | 188 | 5765 | 136 | 986 | 209 | 4130 | 11925 | 653 | 114 | 34 | 0 | 4483 | 2396 | 689 |
| 10 | 34 | 011 | 139559 | 29607 | 133 | 7849 | 11 | 776 | 599 | 4654 | 18109 | 1774 | 297 | 46 | 15 | 10266 | 3385 | 1317 |
| 11 | 34 | 012 | 161981 | 14825 | 172 | 17919 | 0 | 321 | 543 | 3885 | 16380 | 1193 | 141 | 136 | 0 | 4129 | 3543 | 428 |
| 12 | 34 | 013 | 176797 | 5123 | 115 | 17925 | 71 | 433 | 762 | 3196 | 10866 | 207 | 154 | 66 | 9 | 2256 | 1645 | 505 |
| 13 | 34 | 014 | 129659 | 18482 | 222 | 37101 | 63 | 284 | 591 | 3335 | 20948 | 1050 | 28 | 167 | 7 | 4978 | 2207 | 849 |
| 14 | 34 | 015 | 88586 | 55027 | 407 | 23661 | 29 | 161 | 278 | 3645 | 23449 | 2288 | 525 | 35 | 164 | 9688 | 4578 | 468 |
| 15 | 34 | 016 | 138275 | 11402 | 512 | 48874 | 29 | 1049 | 1224 | 4449 | 12458 | 581 | 168 | 51 | 46 | 3262 | 2454 | 458 |
| 16 | 34 | 017 | 70856 | 45295 | 353 | 52596 | 24 | 1699 | 1144 | 3791 | 31629 | 2269 | 474 | 129 | 6 | 13613 | 2775 | 602 |
| 17 | 34 | 018 | 96906 | 16389 | 144 | 69965 | 198 | 1125 | 1769 | 4270 | 13519 | 716 | 107 | 139 | 9 | 7926 | 3235 | 1546 |
| 18 | 34 | 019 | 82172 | 21725 | 234 | 37332 | 91 | 1005 | 836 | 2655 | 52658 | 3034 | 493 | 348 | 42 | 15201 | 7470 | 2693 |
| 19 | 34 | 020 | 43416 | 64102 | 124 | 9020 | 32 | 6246 | 1034 | 2581 | 39353 | 3078 | 894 | 278 | 0 | 50647 | 8436 | 1632 |
| 20 | 34 | 021 | 157029 | 7157 | 130 | 23822 | 4 | 2092 | 178 | 4102 | 13664 | 764 | 27 | 252 | 9 | 6667 | 3113 | 745 |
| 21 | 34 | 022 | 85166 | 48110 | 302 | 10880 | 0 | 1933 | 526 | 3266 | 30431 | 2802 | 751 | 82 | 53 | 27643 | 6986 | 1867 |
| 22 | 34 | 023 | 158090 | 8589 | 137 | 17450 | 67 | 547 | 823 | 2975 | 14501 | 537 | 76 | 227 | 10 | 5269 | 3280 | 900 |
| 23 | 34 | 024 | 172261 | 5102 | 54 | 5774 | 0 | 366 | 550 | 3145 | 13744 | 509 | 33 | 38 | 18 | 2185 | 2191 | 778 |
| 24 | 34 | 025 | 149612 | 8463 | 95 | 12998 | 0 | 520 | 435 | 4235 | 23251 | 561 | 398 | 33 | 43 | 8778 | 3354 | 1009 |
| 25 | 34 | 026 | 158999 | 3980 | 312 | 29933 | 68 | 560 | 710 | 3779 | 15035 | 276 | 187 | 124 | 0 | 2051 | 1752 | 515 |
| 26 | 34 | 027 | 135411 | 27575 | 149 | 27637 | 47 | 1903 | 600 | 5410 | 13974 | 1106 | 117 | 71 | 10 | 4368 | 3807 | 949 |
| 27 | 34 | 028 | 48262 | 124943 | 418 | 9828 | 0 | 1361 | 1550 | 3354 | 19526 | 2941 | 144 | 143 | 6 | 11208 | 3433 | 2255 |
| 28 | 34 | 029 | 39357 | 69740 | 518 | 6621 | 133 | 3461 | 775 | 2477 | 51169 | 4322 | 444 | 140 | 78 | 35428 | 11447 | 2838 |
| 29 | 34 | 030 | 198248 | 5260 | 79 | 4598 | 0 | 361 | 560 | 1229 | 13560 | 498 | 163 | 19 | 0 | 7169 | 2567 | 499 |
| 30 | 34 | 031 | 61153 | 54849 | 533 | 48350 | 68 | 1749 | 1560 | 4958 | 26783 | 4000 | 426 | 575 | 0 | 23355 | 6615 | 2378 |
| 31 | 34 | 032 | 61149 | 6135 | 235 | 25696 | 0 | 1031 | 920 | 2492 | 73439 | 2620 | 1182 | 731 | 38 | 42161 | 14261 | 3065 |
| 32 | 34 | 033 | 79083 | 10164 | 264 | 36231 | 280 | 994 | 886 | 4272 | 53524 | 4358 | 744 | 366 | 13 | 21507 | 10898 | 2940 |
| 33 | 34 | 034 | 62307 | 86049 | 245 | 11297 | 22 | 1408 | 1534 | 3534 | 23737 | 2531 | 244 | 73 | 86 | 20076 | 4877 | 1035 |
| 34 | 34 | 035 | 48580 | 41180 | 60 | 9525 | 8 | 994 | 418 | 2014 | 45974 | 2416 | 256 | 116 | 35 | 54886 | 10741 | 2598 |
| 35 | 34 | 036 | 96442 | 8583 | 293 | 24153 | 90 | 779 | 591 | 2463 | 59863 | 1956 | 538 | 391 | 6 | 15771 | 14727 | 1889 |
| 36 | 34 | 037 | 83635 | 28162 | 285 | 55617 | 44 | 949 | 1060 | 3964 | 32260 | 2368 | 289 | 169 | 23 | 8331 | 4299 | 3252 |
| 37 | 34 | 038 | 125937 | 9772 | 342 | 33934 | 43 | 578 | 467 | 3175 | 29169 | 1151 | 261 | 254 | 12 | 5890 | 5918 | 1866 |
| 38 | 34 | 039 | 159377 | 4062 | 328 | 26230 | 0 | 550 | 971 | 3655 | 17047 | 730 | 100 | 278 | 0 | 2499 | 2966 | 954 |
| 39 | 34 | 040 | 164360 | 4799 | 219 | 17246 | 129 | 508 | 428 | 3114 | 16899 | 361 | 27 | 72 | 0 | 3039 | 3884 | 604 |
Error Handling
What happens if we get one of the keywords wrong? We can always look a few cells up at the output from cgeo.geo_path_snake_specs, but we also get a friendly exception message to tell us what the options are.
[10]:
try:
ced.download_detail(DATASET, YEAR, leaves, state=STATE_NJ, unknown_geo="*")
except ced.CensusApiException as e:
print(e)
Unable to match the geography specification {'state': '34', 'unknown_geo': '*'}.
Supported geographies for dataset='acs/acs5' in year=2020 are:
['us']
['region']
['division']
['state']
['state', 'county']
['state', 'county', 'county_subdivision']
['state', 'county', 'county_subdivision', 'subminor_civil_division']
['state', 'county', 'county_subdivision', 'place_remainder_or_part']
['state', 'county', 'tract']
['state', 'county', 'tract', 'block_group']
['state', 'place', 'county_or_part']
['state', 'place']
['state', 'consolidated_city']
['state', 'consolidated_city', 'place_or_part']
['state', 'alaska_native_regional_corporation']
['american_indian_area_alaska_native_area_hawaiian_home_land']
['american_indian_area_alaska_native_area_hawaiian_home_land', 'tribal_subdivision_remainder']
['american_indian_area_alaska_native_area_reservation_or_statistical_entity_only']
['american_indian_area_off_reservation_trust_land_only_hawaiian_home_land']
['american_indian_area_alaska_native_area_hawaiian_home_land', 'tribal_census_tract']
['american_indian_area_alaska_native_area_hawaiian_home_land', 'tribal_census_tract', 'tribal_block_group']
['american_indian_area_alaska_native_area_hawaiian_home_land', 'state_or_part']
['american_indian_area_alaska_native_area_hawaiian_home_land', 'state_or_part', 'place_remainder_or_part']
['american_indian_area_alaska_native_area_hawaiian_home_land', 'state_or_part', 'county_or_part']
['state', 'american_indian_area_alaska_native_area_hawaiian_home_land_or_part']
['state', 'american_indian_area_alaska_native_area_reservation_or_statistical_entity_only_or_part']
['state', 'american_indian_area_off_reservation_trust_land_only_hawaiian_home_land_or_part']
['american_indian_area_alaska_native_area_hawaiian_home_land', 'tribal_subdivision_remainder', 'state_or_part']
['american_indian_area_reservation_only', 'tribal_census_tract_or_part']
['american_indian_area_off_reservation_trust_land_only_hawaiian_home_land', 'tribal_census_tract_or_part']
['american_indian_area_reservation_only', 'tribal_census_tract_or_part', 'tribal_block_group_or_part']
['american_indian_area_off_reservation_trust_land_only_hawaiian_home_land', 'tribal_census_tract_or_part', 'tribal_block_group_or_part']
['metropolitan_statistical_area_micropolitan_statistical_area']
['metropolitan_statistical_area_micropolitan_statistical_area', 'state_or_part']
['metropolitan_statistical_area_micropolitan_statistical_area', 'state_or_part', 'principal_city_or_part']
['metropolitan_statistical_area_micropolitan_statistical_area', 'state_or_part', 'county']
['metropolitan_statistical_area_micropolitan_statistical_area', 'metropolitan_division']
['metropolitan_statistical_area_micropolitan_statistical_area', 'metropolitan_division', 'state_or_part']
['metropolitan_statistical_area_micropolitan_statistical_area', 'metropolitan_division', 'state_or_part', 'county']
['state', 'metropolitan_statistical_area_micropolitan_statistical_area_or_part']
['state', 'metropolitan_statistical_area_micropolitan_statistical_area_or_part', 'principal_city_or_part']
['state', 'metropolitan_statistical_area_micropolitan_statistical_area_or_part', 'county']
['state', 'metropolitan_statistical_area_micropolitan_statistical_area_or_part', 'metropolitan_division_or_part']
['state', 'metropolitan_statistical_area_micropolitan_statistical_area_or_part', 'metropolitan_division_or_part', 'county']
['combined_statistical_area']
['combined_statistical_area', 'state_or_part']
['combined_statistical_area', 'metropolitan_statistical_area_micropolitan_statistical_area']
['combined_statistical_area', 'metropolitan_statistical_area_micropolitan_statistical_area', 'state_or_part']
['combined_new_england_city_and_town_area']
['combined_new_england_city_and_town_area', 'state_or_part']
['combined_new_england_city_and_town_area', 'new_england_city_and_town_area']
['combined_new_england_city_and_town_area', 'new_england_city_and_town_area', 'state_or_part']
['state', 'combined_statistical_area_or_part']
['state', 'combined_statistical_area_or_part', 'metropolitan_statistical_area_micropolitan_statistical_area_or_part']
['state', 'combined_new_england_city_and_town_area_or_part']
['state', 'combined_new_england_city_and_town_area_or_part', 'new_england_city_and_town_area_or_part']
['new_england_city_and_town_area']
['new_england_city_and_town_area', 'state_or_part']
['new_england_city_and_town_area', 'state_or_part', 'principal_city']
['new_england_city_and_town_area', 'state_or_part', 'county_or_part']
['new_england_city_and_town_area', 'state_or_part', 'county_or_part', 'county_subdivision']
['new_england_city_and_town_area', 'necta_division']
['new_england_city_and_town_area', 'necta_division', 'state_or_part']
['new_england_city_and_town_area', 'necta_division', 'state_or_part', 'county_or_part']
['new_england_city_and_town_area', 'necta_division', 'state_or_part', 'county_or_part', 'county_subdivision']
['state', 'new_england_city_and_town_area_or_part']
['state', 'new_england_city_and_town_area_or_part', 'principal_city']
['state', 'new_england_city_and_town_area_or_part', 'county_or_part']
['state', 'new_england_city_and_town_area_or_part', 'county_or_part', 'county_subdivision']
['state', 'new_england_city_and_town_area_or_part', 'necta_division_or_part']
['state', 'new_england_city_and_town_area_or_part', 'necta_division_or_part', 'county_or_part']
['state', 'new_england_city_and_town_area_or_part', 'necta_division_or_part', 'county_or_part', 'county_subdivision']
['urban_area']
['urban_area', 'state']
['urban_area', 'state', 'county']
['state', 'congressional_district']
['state', 'congressional_district', 'county_or_part']
['state', 'congressional_district', 'american_indian_area_alaska_native_area_hawaiian_home_land_or_part']
['state', 'state_legislative_district_upper_chamber']
['state', 'state_legislative_district_upper_chamber', 'county_or_part']
['state', 'state_legislative_district_lower_chamber']
['state', 'state_legislative_district_lower_chamber', 'county_or_part']
['state', 'public_use_microdata_area']
['zip_code_tabulation_area']
['state', 'school_district_elementary']
['state', 'school_district_secondary']
['state', 'school_district_unified']
[ ]: