Create a combined crosswalk for all GEOID resolutions present in geoids.
Handles 11-character tract IDs and 12-character block-group IDs; other
lengths are skipped with a printed notice.
Source code in packages/sdc-census10to20/src/sdc_census10to20/crosswalk.py
| def create_crosswalk(geoids: list[str], *, state_fips: str = "51") -> pd.DataFrame:
"""Create a combined crosswalk for all GEOID resolutions present in ``geoids``.
Handles 11-character tract IDs and 12-character block-group IDs; other
lengths are skipped with a printed notice.
"""
resolutions = sorted({len(g) for g in geoids})
crosswalks: list[pd.DataFrame] = []
for res in resolutions:
if res == 11:
crosswalks.append(
get_2010_2020_bound_changes(res="tract", geoids=geoids, state_fips=state_fips)
)
elif res == 12:
crosswalks.append(
get_2010_2020_bound_changes(
res="block group", geoids=geoids, state_fips=state_fips
)
)
else:
print(f"crosswalk not available for resolution: {res}")
if not crosswalks:
return pd.DataFrame(
columns=["geoid20", "geoid10", "area20", "area10", "area_part", "type_change"]
)
return pd.concat(crosswalks, ignore_index=True)
|