censusdata package

Submodules

censusdata.censusgeo module

class censusdata.censusgeo.censusgeo(geo, name=”)

Bases: object

Class for representing American Community Survey geographies.

hierarchy()

Geography hierarchy for the geographic level of this object.

Returns:
String representing the geography hierarchy (e.g., ‘state> county’).
request()

Generate geographic parameters for Census API request.

Returns:
Dictionary with appropriate ‘for’ and, if needed, ‘in’ parameters for Census API request.
sumlevel()

Summary level code for the geographic level of this object.

Returns:
String representing the summary level code for this object’s geographic level, e.g., ‘050’ for ‘state> county’.
sumleveldict = {‘us’: ‘010’, ‘region’: ‘020’, ‘division’: ‘030’, ‘state’: ‘040’, ‘state> county’: ‘050’, ‘state> county> county subdivision’: ‘060’, ‘state> county> county subdivision> subminor civil division’: ‘067’, ‘state> county> county subdivision> place remainder’: ‘070’, ‘state> county> tract’: ‘140’, ‘state> county> tract> block group’: ‘150’, ‘state> place> county’: ‘155’, ‘state> place’: ‘160’, ‘state> consolidated city’: ‘170’, ‘state> consolidated city> place’: ‘172’, ‘state> alaska native regional corporation’: ‘230’, ‘american indian area/alaska native area/hawaiian home land’: ‘250’, ‘american indian area/alaska native area/hawaiian home land> tribal subdivision/remainder’: ‘251’, ‘american indian area/alaska native area (reservation or statistical entity only)’: ‘252’, ‘american indian area (off-reservation trust land only)/hawaiian home land’: ‘254’, ‘american indian area/alaska native area/hawaiian home land> tribal census tract’: ‘256’, ‘american indian area/alaska native area/hawaiian home land> tribal census tract> tribal block group’: ‘258’, ‘american indian area/alaska native area/hawaiian home land> state’: ‘260’, ‘american indian area/alaska native area/hawaiian home land> state> place/remainder’: ‘269’, ‘american indian area/alaska native area/hawaiian home land> state> county’: ‘270’, ‘state> american indian area/alaska native area/hawaiian home land’: ‘280’, ‘state> american indian area/alaska native area (reservation or statistical entity only)’: ‘283’, ‘state> american indian area (off-reservation trust land only)/hawaiian home land’: ‘286’, ‘american indian area/alaska native area/hawaiian home land> tribal subdivision/remainder> state’: ‘290’, ‘american indian area/alaska native area/hawaiian home land> tribal census tract (or part) within aia (reservation only)’: ‘291’, ‘american indian area/alaska native area/hawaiian home land> tribal census tract (or part) within aia (trust land only)’: ‘292’, ‘american indian area/alaska native area/hawaiian home land> tribal census tract> tribal block group (or part) within tribal census tract within aia (reservation only)’: ‘293’, ‘american indian area/alaska native area/hawaiian home land> tribal census tract> tribal block group (or part) within tribal census tract within aia (trust land only)’: ‘294’, ‘metropolitan statistical area/micropolitan statistical area’: ‘310’, ‘metropolitan statistical area/micropolitan statistical area> state’: ‘311’, ‘metropolitan statistical area/micropolitan statistical area> state> principal city’: ‘312’, ‘metropolitan statistical area/micropolitan statistical area> metropolitan division’: ‘314’, ‘metropolitan statistical area> metropolitan division> state’: ‘315’, ‘state> metropolitan statistical area/micropolitan statistical area’: ‘320’, ‘state> metropolitan statistical area/micropolitan statistical area> principal city (or part)’: ‘321’, ‘state> metropolitan statistical area/micropolitan statistical area> county’: ‘322’, ‘state> metropolitan statistical area/micropolitan statistical area> metropolitan division’: ‘323’, ‘state> metropolitan statistical area/micropolitan statistical area> metropolitan division> county’: ‘324’, ‘combined statistical area’: ‘330’, ‘combined statistical area> state’: ‘331’, ‘combined statistical area> micropolitan statistical area’: ‘332’, ‘combined statistical area> metropolitan statistical area/micropolitan statistical area> state’: ‘333’, ‘combined new england city and town area’: ‘335’, ‘combined new england city and town area> state’: ‘336’, ‘combined new england city and town area> new england city and town area’: ‘337’, ‘combined new england city and town area> new england city and town area> state’: ‘338’, ‘state> combined statistical area’: ‘340’, ‘state> combined statistical area> metropolitan statistical area/micropolitan statistical area’: ‘341’, ‘state> combined new england city and town area’: ‘345’, ‘state> combined new england city and town area> new england city and town area’: ‘346’, ‘new england city and town area’: ‘350’, ‘new england city and town area> state’: ‘351’, ‘new england city and town area> state> principal city’: ‘352’, ‘new england city and town area> necta division’: ‘355’, ‘new england city and town area> necta division> state’: ‘356’, ‘state> new england city and town area’: ‘360’, ‘state> new england city and town area> place’: ‘361’, ‘state> new england city and town area> county’: ‘362’, ‘state> new england city and town area> county> county subdivision’: ‘363’, ‘state> new england city and town area> necta division’: ‘364’, ‘state> new england city and town area> necta division> county’: ‘365’, ‘state> new england city and town area> necta division> county> county subdivision’: ‘366’, ‘urban area’: ‘400’, ‘urban area> state’: ‘410’, ‘urban area> state> county’: ‘430’, ‘state> congressional district’: ‘500’, ‘state> congressional district> county’: ‘510’, ‘state> congressional district> american indian area/alaska native area/hawaiian home land’: ‘550’, ‘state> state legislative district (upper chamber)’: ‘610’, ‘state> state legislative district (upper chamber)> county’: ‘612’, ‘state> state legislative district (lower chamber)’: ‘620’, ‘state> state legislative district (lower chamber)> county’: ‘622’, ‘state> public use microdata area’: ‘795’, ‘zip code tabulation area’: ‘860’, ‘state> school district (elementary)’: ‘950’, ‘state> school district (secondary)’: ‘960’, ‘state> school district (unified)’: ‘970’}

dict: Census summary level codes for different types of geography

censusdata.download module

Functions for downloading data and lists of geographies from the Census API.

censusdata.download.download(src, year, geo, var, key=None, tabletype=’detail’)

Download data from Census API.

Args:
src (str): Census data source. year (str): Year of data. var (list of str): Census variables to download. key (str, optional): Census API key. tabletype (str, optional): Type of table from which variables are drawn. Options are ‘detail’ (detail tables), ‘subject’ (subject tables), ‘profile’ (data profile tables), ‘cprofile’ (comparison profile tables).
Returns:
pandas.DataFrame with columns corresponding to designated variables, and row index of censusgeo objects representing Census geographies.
Raises:
ValueError: If unknown tabletype is specified.

Examples:

censusdata.download.geographies(within, src, year, key=None)

List geographies within a given geography, e.g., counties within a state.

Args:
within (censusgeo): Geography within which to list geographies. src (str): Census data source. year (str): Year of data. key (str, optional): Census API key.
Returns:
Dictionary with names as keys and censusgeo objects as values.

Examples:

censusdata.export module

Functions to faciliate exporting data downloaded from Census API.

censusdata.export.exportcsv(file, data)

Export Pandas DataFrame where index is composed of censusgeo objects. Can be used with return value from download().

Args:
file: String or file handler for exporting data. data: Data to export.
Returns:
None.

censusdata.variable_info module

Functions for showing information about Census variables.

censusdata.variable_info.censustable(src, year, table)

Show information on all variables in a table.

censusdata.variable_info.censusvar(src, year, var)

Download information on a list of variables from Census API.

censusdata.variable_info.printtable(table, moe=False)

Pretty print information on a Census table (such as produced by censustable).

censusdata.variable_info.search(src, year, field, criterion, tabletype=’detail’)

Search Census variables.

Module contents