The query Module

query.py

Functions for Requesting Data from the Census API

get_census_data(year: int, variables: list, geography: str, dataset: str, sum_file: Optional[str] = None, key: Optional[str] = None, state: Optional[str] = None, county: Optional[str] = None)[source]
Parameters
  • year – Year of data that we are querying

  • variables – list of strings containing the census variable names to request

  • geography – Geographic resolution we’re querying at (zcta, county, state)

  • dataset – The census data set you want (dec, acs1, acs5, pums)

  • sum_file – For the 2000 census, sf1 or sf3

  • key – Your census API key. We recommend not passing it here and instead either setting the “CENSUS_API_KEY” environmental variable or using the set_api_key function.

  • state – 2 digit FIPS code of the state you want to limit the query to (i.e. “06” for CA)

  • county – 3 digit FIPS code of the county you want to include. Requires state to be specified

Returns

a pandas DataFrame

api_geography(geo: str)[source]

go from function shorthand to the input the census api needs

Parameters

geo – shorthand for a given geography type

Returns

corrected geography name