https://github.com/datamade/census
import os
from census import Census
from us import states
census_client = Census(os.environ.get("CENSUS_DATA_API_KEY"))
datasets:
Tract -> Block group -> Block
https://data.census.gov/table/ACSDT1Y2024.B01001 - Sex by age, American Community Survey
https://data.census.gov/table/ACSDT1Y2024.B25040 - Occupied housing units by their primary heating source
https://data.census.gov/table/ACSDT5Y2024.B25034 - Year house built
https://data.census.gov/table/ACSDT1Y2024.B25024 - Units in structure
https://data.census.gov/table/ACSDT1Y2024.B25003 - Renters and owners
https://data.census.gov/table/ACSDT1Y2024.B19013 - Median household esimate
census_client.acs5.state(('NAME', 'B01003_001E'), states.MD.fips)
fields = [
"NAME",
"B01003_001E", # Total population estimate
]
rows = census_client.acs5.state_county_tract(
fields,
state_fips="24", # Maryland
county_fips="003", # Anne Arundel County
tract=Census.ALL,
year=2024,
)
rows = census_client.acs5.state_county_blockgroup(
fields,
state_fips="24", # Maryland
county_fips="003", # Anne Arundel County
blockgroup=Census.ALL,
year=2024,
)
df = pd.DataFrame(rows)