The census_info Module

census_info.py

Core module for handling census metadata

get_endpoint(year: int, dataset: str, sum_file: Optional[str] = None)[source]

Returns a string containing the URL to the census API endpoint

Parameters
  • year – The year for which you want data

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

  • sum_file – For the 2000 census, sf1 or sf3

Returns

get_varlist(year: int, dataset: str, sum_file: Optional[str] = None)[source]
Parameters
  • year – Year of data

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

  • sum_file – For the 2000 census, sf1 or sf3

Returns

Dataframe of available variables in a given data set

set_api_key(key: str)[source]

Sets an environment variable to contain your census API key. To avoid needing to run this every session you can also permanently set CENSUS_API_KEY to your key in your environment.

Parameters

key – Your Census API key as a string

Returns

nothing

census_years(min_year: int = 2000, max_year: int = 2019)[source]

Constructs a list of years for which census data is available in the range provided. At this point assumes we want the decennial census and acs5. Future functionality might expand to allow this to vary.

Parameters
  • min_year – minimum year we want data for

  • max_year – max year we want data for (inclusive)

Returns

list of all years in specified range for which data is available