def main(): pd.set_option('display.expand_frame_repr', False) pd.set_option('display.precision', 2) #to download we must identify the tables containing the variables interest to us. #use ACS documentation, in particular Table Shells (https://www.census.gov/programs-surveys/acs/technical-documentation/summary-file-documentation.html) #can use cenusdata.search to find given text patterns. We can limit the output to the relevenant variables censusdata.search('acs5', 2015, 'label', 'unemploy')[160:170] censusdata.search('acs5', 2015, 'concept', 'education')[730:790] #using censusdata.printtable to show vars in table censusdata.printtable(censusdata.censustable('acs5', 2015, 'B23025')) censusdata.printtable(censusdata.censustable('acs5', 2015, 'B15003')) #after getting relevant variables, we need to identify the geographies. #we are going to get block groups in Cook County IL #1. look for FIPS code #2. find identifiers for all counties within IL to find Cook #1 #print(censusdata.geographies(censusdata.censusgeo([('state','*')]), 'acs5', 2015)) #IL is 17 #2 #print(censusdata.geographies(censusdata.censusgeo([('state','17'), ('county', '*')]), 'acs5', 2015)) #cook is 031 #once we have identified variables and geos of interest, #we can download the data using censusdata.download. compute variables for the percent unemployed and the percent w no hs degree cook_cnty = censusdata.download('acs5', 2015, censusdata.censusgeo([('state','17'), ('county','031'), ('block group','*')]), ['B23025_003E', 'B23025_005E', 'B15003_001E', 'B15003_002E', 'B15003_003E','B15003_004E', 'B15003_005E', 'B15003_006E', 'B15003_007E', 'B15003_008E','B15003_009E', 'B15003_010E', 'B15003_011E', 'B15003_012E', 'B15003_013E','B15003_014E', 'B15003_015E', 'B15003_016E']) cook_cnty['percent_unemployed'] = cook_cnty.B23025_005E / cook_cnty.B23025_003E * 100 cook_cnty['percent_nohs'] = (cook_cnty.B15003_002E + cook_cnty.B15003_003E + cook_cnty.B15003_004E + cook_cnty.B15003_005E + cook_cnty.B15003_006E + cook_cnty.B15003_007E + cook_cnty.B15003_008E + cook_cnty.B15003_009E + cook_cnty.B15003_010E + cook_cnty.B15003_011E + cook_cnty.B15003_012E + cook_cnty.B15003_013E + cook_cnty.B15003_014E + cook_cnty.B15003_015E + cook_cnty.B15003_016E) / cook_cnty.B15003_001E * 100 cook_cnty = cook_cnty[['percent_unemployed', 'percent_nohs']] print(cook_cnty.describe()) #to show the 30 block groups in cook w highest rate of unemployment and the percent w no hs degree print(cook_cnty.sort_values('percent_unemployed', ascending=False).head(30)) #show correlation print(cook_cnty.corr()) censusdata.exportcsv('cook_data.csv', cook_cnty)
def test_printtable(self): testtable = censusdata.censustable('acs5', 2015, 'B19013') printedtable = io.StringIO() sys.stdout = printedtable censusdata.printtable(testtable) sys.stdout = sys.__stdout__ self.assertEqual( printedtable.getvalue(), textwrap.dedent('''\ Variable | Table | Label | Type ------------------------------------------------------------------------------------------------------------------- B19013_001E | MEDIAN HOUSEHOLD INCOME IN THE | !! Estimate Median household income in the past 12 month | int ------------------------------------------------------------------------------------------------------------------- ''')) printedtable.close() printedtable = io.StringIO() sys.stdout = printedtable censusdata.printtable(testtable, moe=True) sys.stdout = sys.__stdout__ self.assertEqual( printedtable.getvalue(), textwrap.dedent('''\ Variable | Table | Label | Type ------------------------------------------------------------------------------------------------------------------- B19013_001E | MEDIAN HOUSEHOLD INCOME IN THE | !! Estimate Median household income in the past 12 month | int ------------------------------------------------------------------------------------------------------------------- ''')) printedtable.close()
def test_censustable_sf1(self): expected = OrderedDict() expected['P002001'] = { 'label': 'Total', 'concept': 'URBAN AND RURAL', 'predicateType': 'int' } expected['P002002'] = { 'label': 'Total!!Urban', 'concept': 'URBAN AND RURAL', 'predicateType': 'int' } expected['P002003'] = { 'label': 'Total!!Urban!!Inside urbanized areas', 'concept': 'URBAN AND RURAL', 'predicateType': 'int' } expected['P002004'] = { 'label': 'Total!!Urban!!Inside urban clusters', 'concept': 'URBAN AND RURAL', 'predicateType': 'int' } expected['P002005'] = { 'label': 'Total!!Rural', 'concept': 'URBAN AND RURAL', 'predicateType': 'int' } expected['P002006'] = { 'label': 'Total!!Not defined for this file', 'concept': 'URBAN AND RURAL', 'predicateType': 'int' } self.assertEqual(censusdata.censustable('sf1', 2010, 'P002'), expected)
def fetch_variables_and_labels(table, survey=survey, year=year): results = censusdata.censustable(survey, year, table) result_variables = [] result_labels = [] for (value, info) in results.items(): result_variables.append(value) result_labels.append(re.sub(r".*[!!]", '', info['label'])) return (result_variables, result_labels)
def get_census_demo(): variables = [ i for tid in table_ids.keys() for i in censusdata.censustable('acs5', 2015, tid) ] data_dict = {} for tid in table_ids.keys(): for (elt, v) in censusdata.censustable('acs5', 2015, tid).items(): data_dict[elt] = v['concept'] + ' | ' + v['label'] county_data = censusdata.download( 'acs5', 2015, censusdata.censusgeo([('state', '*'), ('county', '*')]), variables) def get_fips(county): # concat state and county fips from string state_fips = county.split('state:')[1].split('>')[0] county_fips = county.split('> county:')[1] return state_fips + county_fips def get_county_names(county): # extract county names from string return str(county).split(':')[0] county_data['county_name'] = [ get_county_names(str(x)) for x in county_data.index ] county_data['county_id'] = [ get_fips(str(x)) if x else 'NaN' for x in county_data.index ] county_data = county_data.reset_index(drop=True).set_index('county_id') county_data.to_csv('./data/groomed_data/county_census.csv', index=False) with open('./data/groomed_data/county_census_data_dict.json', 'w') as f: f.write(json.dumps(data_dict)) return county_data
def test_censustable_acs5_2017_detail(self): expected = OrderedDict() expected['B23025_001E'] = { 'label': 'Estimate!!Total', 'concept': 'EMPLOYMENT STATUS FOR THE POPULATION 16 YEARS AND OVER', 'predicateType': 'int' } expected['B23025_002E'] = { 'label': 'Estimate!!Total!!In labor force', 'concept': 'EMPLOYMENT STATUS FOR THE POPULATION 16 YEARS AND OVER', 'predicateType': 'int' } expected['B23025_003E'] = { 'label': 'Estimate!!Total!!In labor force!!Civilian labor force', 'concept': 'EMPLOYMENT STATUS FOR THE POPULATION 16 YEARS AND OVER', 'predicateType': 'int' } expected['B23025_004E'] = { 'label': 'Estimate!!Total!!In labor force!!Civilian labor force!!Employed', 'concept': 'EMPLOYMENT STATUS FOR THE POPULATION 16 YEARS AND OVER', 'predicateType': 'int' } expected['B23025_005E'] = { 'label': 'Estimate!!Total!!In labor force!!Civilian labor force!!Unemployed', 'concept': 'EMPLOYMENT STATUS FOR THE POPULATION 16 YEARS AND OVER', 'predicateType': 'int' } expected['B23025_006E'] = { 'label': 'Estimate!!Total!!In labor force!!Armed Forces', 'concept': 'EMPLOYMENT STATUS FOR THE POPULATION 16 YEARS AND OVER', 'predicateType': 'int' } expected['B23025_007E'] = { 'label': 'Estimate!!Total!!Not in labor force', 'concept': 'EMPLOYMENT STATUS FOR THE POPULATION 16 YEARS AND OVER', 'predicateType': 'int' } self.assertEqual(censusdata.censustable('acs5', 2017, 'B23025'), expected)
def _parse_table_str(self, table_str): """Return table_id from table str""" if isinstance(table_str, dict): return table_str base_table_id = self.tables_dict[table_str] tables_dict = censusdata.censustable(self.survey, self.year, base_table_id) final_table_dict = {} for table_id, table_dict in tables_dict.items(): table_label = table_dict["concept"] + "!!" + table_dict["label"] table_id_moe = table_id.replace("E", "M") table_label_moe = "MOE!!" + table_label final_table_dict.update({ table_id: table_label, table_id_moe: table_label_moe }) return final_table_dict
def test_censustable_acsse(self): for year in range(2014, 2015 + 1): censusdata.censustable('acsse', year, 'K201601') for year in range(2016, 2018 + 1): censusdata.censustable('acsse', year, 'K201601') censusdata.censustable('acsse', 2019, 'K201601')
def test_censustable_acs5_2019_detail(self): expected = OrderedDict() expected['B23025_001E'] = { 'label': 'Estimate!!Total:', 'concept': 'EMPLOYMENT STATUS FOR THE POPULATION 16 YEARS AND OVER', 'predicateType': 'int' } expected['B23025_002E'] = { 'label': 'Estimate!!Total:!!In labor force:', 'concept': 'EMPLOYMENT STATUS FOR THE POPULATION 16 YEARS AND OVER', 'predicateType': 'int' } expected['B23025_003E'] = { 'label': 'Estimate!!Total:!!In labor force:!!Civilian labor force:', 'concept': 'EMPLOYMENT STATUS FOR THE POPULATION 16 YEARS AND OVER', 'predicateType': 'int' } expected['B23025_004E'] = { 'label': 'Estimate!!Total:!!In labor force:!!Civilian labor force:!!Employed', 'concept': 'EMPLOYMENT STATUS FOR THE POPULATION 16 YEARS AND OVER', 'predicateType': 'int' } expected['B23025_005E'] = { 'label': 'Estimate!!Total:!!In labor force:!!Civilian labor force:!!Unemployed', 'concept': 'EMPLOYMENT STATUS FOR THE POPULATION 16 YEARS AND OVER', 'predicateType': 'int' } expected['B23025_006E'] = { 'label': 'Estimate!!Total:!!In labor force:!!Armed Forces', 'concept': 'EMPLOYMENT STATUS FOR THE POPULATION 16 YEARS AND OVER', 'predicateType': 'int' } expected['B23025_007E'] = { 'label': 'Estimate!!Total:!!Not in labor force', 'concept': 'EMPLOYMENT STATUS FOR THE POPULATION 16 YEARS AND OVER', 'predicateType': 'int' } self.assertEqual(censusdata.censustable('acs5', 2019, 'B23025'), expected) expected = OrderedDict() expected['C15010_001E'] = { 'label': 'Estimate!!Total:', 'concept': "FIELD OF BACHELOR'S DEGREE FOR FIRST MAJOR FOR THE POPULATION 25 YEARS AND OVER", 'predicateType': 'int' } expected['C15010_002E'] = { 'label': 'Estimate!!Total:!!Science and Engineering', 'concept': "FIELD OF BACHELOR'S DEGREE FOR FIRST MAJOR FOR THE POPULATION 25 YEARS AND OVER", 'predicateType': 'int' } expected['C15010_003E'] = { 'label': 'Estimate!!Total:!!Science and Engineering Related Fields', 'concept': "FIELD OF BACHELOR'S DEGREE FOR FIRST MAJOR FOR THE POPULATION 25 YEARS AND OVER", 'predicateType': 'int' } expected['C15010_004E'] = { 'label': 'Estimate!!Total:!!Business', 'concept': "FIELD OF BACHELOR'S DEGREE FOR FIRST MAJOR FOR THE POPULATION 25 YEARS AND OVER", 'predicateType': 'int' } expected['C15010_005E'] = { 'label': 'Estimate!!Total:!!Education', 'concept': "FIELD OF BACHELOR'S DEGREE FOR FIRST MAJOR FOR THE POPULATION 25 YEARS AND OVER", 'predicateType': 'int' } expected['C15010_006E'] = { 'label': 'Estimate!!Total:!!Arts, Humanities and Other', 'concept': "FIELD OF BACHELOR'S DEGREE FOR FIRST MAJOR FOR THE POPULATION 25 YEARS AND OVER", 'predicateType': 'int' } self.assertEqual(censusdata.censustable('acs5', 2019, 'C15010'), expected)
# %% import censusdata import pandas as pd import sqlite3 import ssl import re import os pd.set_option('display.expand_frame_repr', False) pd.set_option('display.precision', 2) # %% # Aggregate Population by Age censusdata.printtable(censusdata.censustable('acs5', 2018, 'B01001')) # %% # Geographies by state>place censusdata.geographies(censusdata.censusgeo([('state', '12'), ('place', '*')]), 'acs5', 2018) # %% # By County censusdata.geographies( censusdata.censusgeo([('state', '12'), ('county', '*')]), 'acs5', 2018) # %% # By County Subdivision censusdata.geographies( censusdata.censusgeo([('state', '12'), ('county', '057'), ('county subdivision', '*')]), 'acs5', 2018) # %%
key=KEY) # In[4]: state_dict_lookup = {v.geo[0][1]: k for k, v in state_dict.items()} state_dict_lookup # In[5]: # allegheny is '003' for testing county_dict = censusdata.geographies(censusdata.censusgeo([('state', '42'), ('county', '*')]), 'acs5', 2015, key=KEY) sex_by_age_table_info_dict = censusdata.censustable('acs5', 2015, 'B01001') # In[6]: county_dict_lookup = { v.geo[1][1]: " ".join(k.split(',')[0].split(' ')[:-1]) for k, v in county_dict.items() } county_dict_lookup # In[7]: # pennsylvania is 42 # get all county codes from above dictionary and loop through them with this pa_state_code = '42'
#Creating dictionary mapping for census tract to zipcode #to be able to map the census data to education data census_zipcode_relation_filename = 'zcta_tract.csv' census_zipcode_relation = pd.read_csv(census_zipcode_relation_filename, \ delimiter=',', dtype=str) ny_tract_to_zipcode = census_zipcode_relation[census_zipcode_relation\ ['STATE'] == '36'][['TRACT', 'ZCTA5']] tract_zipcode = {} for row in ny_tract_to_zipcode.itertuples(): tract_zipcode[row[1]] = row[2] #Obtaining 2010 Census median income data for each borough in NYC censusdata.search('acs5', 2015, 'label', 'median income') censusdata.censustable('acs5', 2015, 'B06011') median_income_bronx = censusdata.download('acs5', 2015, \ censusdata.censusgeo([('state', '36'), ('county', '005'), \ ('tract', '*')]), ['B06011_001E']) median_income_kings = censusdata.download('acs5', 2015, \ censusdata.censusgeo([('state', '36'), ('county', '047'), \ ('tract', '*')]), ['B06011_001E']) median_income_ny = censusdata.download('acs5', 2015, \ censusdata.censusgeo([('state', '36'), ('county', '061'), \ ('tract', '*')]), ['B06011_001E']) median_income_queens = censusdata.download('acs5', 2015, \ censusdata.censusgeo([('state', '36'), ('county', '081'), \ ('tract', '*')]), ['B06011_001E']) median_income_richmond = censusdata.download('acs5', 2015, \ censusdata.censusgeo([('state', '36'), ('county', '085'), \ ('tract', '*')]), ['B06011_001E'])
def test_censustable_acs3(self): for year in range(2012, 2013 + 1): censusdata.censustable('acs3', year, 'B23025')
def test_censustable_acs_subject_full(self): censusdata.censustable('acs5', 2018, 'S1810')
def genTable(table): return censusdata.printtable(censusdata.censustable('acs1', 2018, table))
input_drive = 'data/raw' table_shell = os.path.join(input_drive, 'ACS2017_Table_Shells.xlsx') xl = pd.ExcelFile(table_shell) table_shell_df = xl.parse(xl.sheet_names[0]) # variables I've flagged to use use_vars = table_shell_df[table_shell_df.Use == 1] print(use_vars[['TableID', 'Stub', 'Use']]) use_vars.to_csv(os.path.join(input_drive, 'ACS_variables.csv')) variables = use_vars.TableID.tolist() # Use the census data package # Examples of functionality censusdata.search('acs5', 2017, 'label', 'unemploy') # censusdata.search('acs5', 2017, 'concept', 'education') censusdata.printtable(censusdata.censustable('acs5', 2017, 'B23025')) censusdata.geographies(censusdata.censusgeo([('state', '*')]), 'acs5', 2017) censusdata.geographies( censusdata.censusgeo([('state', '08'), ('county', '*')]), 'acs5', 2017) # doesn't seem like the C variables work, so remove them variables = [var for var in variables if 'C' not in var] variables = [var for var in variables if "B17002" not in var] # loop through all variables and merge data together count = 0 for variable in variables: print(variable) data = censusdata_pull(variable) if count == 0:
def test_censustable_acs1_201219_detail(self): for year in range(2012, 2019 + 1): censusdata.censustable('acs1', year, 'B23025')
def test_censustable_acs5_2015_detail(self): censusdata.censustable('acs5', 2015, 'B23025')
def main(verbose=False, data_dir='../data/'): if verbose: pd.set_option('display.expand_frame_repr', False) pd.set_option('display.precision', 2) print("Available race variables:") print(censusdata.search('acs5', 2015, 'label', 'race')) print("Table to download:") censusdata.printtable(censusdata.censustable('acs5', 2015, 'B02001')) variables = list(censusdata.censustable('acs5', 2015, 'B02001').keys()) # remove variables for margin of errors variables = list(filter(lambda x: x[-1] != 'M', variables)) if verbose: print("Variables:") print(variables) illinois_demo = censusdata.download( 'acs5', 2015, censusdata.censusgeo([('state', '17'), ('tract', '*')]), variables) illinois_demo.rename( { 'B02001_001E': 'total', 'B02001_002E': 'white', 'B02001_003E': 'black', 'B02001_004E': 'native', 'B02001_005E': 'asian', 'B02001_006E': 'pacific', 'B02001_007E': 'other', 'B02001_008E': 'two_or_more', 'B02001_009E': 'two_or_more_including_other', 'B02001_010E': 'two_or_more_excluding_other' }, axis='columns', inplace=True) illinois_demo.other = illinois_demo.other + \ illinois_demo['two_or_more_including_other'] + \ illinois_demo['two_or_more_excluding_other'] illinois_demo = illinois_demo[[ 'total', 'white', 'black', 'native', 'asian', 'pacific', 'other' ]] total = illinois_demo.total illinois_demo.white /= total illinois_demo.black /= total illinois_demo.native /= total illinois_demo.asian /= total illinois_demo.pacific /= total illinois_demo.other /= total illinois_demo['censusgeo'] = illinois_demo.index illinois_demo.reset_index(level=0, drop=True, inplace=True) illinois_demo['tract'] = illinois_demo['censusgeo'].apply( lambda x: x.geo[2][1]).astype(str) illinois_demo['county'] = illinois_demo['censusgeo'].apply( lambda x: x.geo[1][1]) illinois_demo['county_name'] = illinois_demo['censusgeo'].apply( lambda x: x.name.split(',')[1][1:-7]) illinois_demo.drop('censusgeo', axis='columns', inplace=True) if verbose: print(illinois_demo.sample(frac=10 / len(illinois_demo))) print(illinois_demo.describe()) illinois_demo = illinois_demo.loc[illinois_demo.county_name == 'Cook'] illinois_demo.to_csv(data_dir + 'Illinois2015CensusTractsDemographics.csv') print("Successfully downloaded Illinois demographic data.") url = "https://github.com/uscensusbureau/citysdk/raw/master/v2/GeoJSON/500k/2015/17/tract.json" fname = 'Illinois2015CensusTracts.json' target = data_dir + fname download_file(url, target) print("Successfully downloaded Illinois census tract shapefile.")
def test_censustable_acs5_2016_subject(self): censusdata.censustable('acs5', 2016, 'S0101_C02')
def test_censustable_acs5_2019_subject(self): expected = OrderedDict() expected['S0101_C02_001E'] = { 'label': 'Estimate!!Percent!!Total population', 'concept': 'AGE AND SEX', 'predicateType': 'int' } expected['S0101_C02_002E'] = { 'label': 'Estimate!!Percent!!Total population!!AGE!!Under 5 years', 'concept': 'AGE AND SEX', 'predicateType': 'float' } expected['S0101_C02_003E'] = { 'label': 'Estimate!!Percent!!Total population!!AGE!!5 to 9 years', 'concept': 'AGE AND SEX', 'predicateType': 'float' } expected['S0101_C02_004E'] = { 'label': 'Estimate!!Percent!!Total population!!AGE!!10 to 14 years', 'concept': 'AGE AND SEX', 'predicateType': 'float' } expected['S0101_C02_005E'] = { 'label': 'Estimate!!Percent!!Total population!!AGE!!15 to 19 years', 'concept': 'AGE AND SEX', 'predicateType': 'float' } expected['S0101_C02_006E'] = { 'label': 'Estimate!!Percent!!Total population!!AGE!!20 to 24 years', 'concept': 'AGE AND SEX', 'predicateType': 'float' } expected['S0101_C02_007E'] = { 'label': 'Estimate!!Percent!!Total population!!AGE!!25 to 29 years', 'concept': 'AGE AND SEX', 'predicateType': 'float' } expected['S0101_C02_008E'] = { 'label': 'Estimate!!Percent!!Total population!!AGE!!30 to 34 years', 'concept': 'AGE AND SEX', 'predicateType': 'float' } expected['S0101_C02_009E'] = { 'label': 'Estimate!!Percent!!Total population!!AGE!!35 to 39 years', 'concept': 'AGE AND SEX', 'predicateType': 'float' } expected['S0101_C02_010E'] = { 'label': 'Estimate!!Percent!!Total population!!AGE!!40 to 44 years', 'concept': 'AGE AND SEX', 'predicateType': 'float' } expected['S0101_C02_011E'] = { 'label': 'Estimate!!Percent!!Total population!!AGE!!45 to 49 years', 'concept': 'AGE AND SEX', 'predicateType': 'float' } expected['S0101_C02_012E'] = { 'label': 'Estimate!!Percent!!Total population!!AGE!!50 to 54 years', 'concept': 'AGE AND SEX', 'predicateType': 'float' } expected['S0101_C02_013E'] = { 'label': 'Estimate!!Percent!!Total population!!AGE!!55 to 59 years', 'concept': 'AGE AND SEX', 'predicateType': 'float' } expected['S0101_C02_014E'] = { 'label': 'Estimate!!Percent!!Total population!!AGE!!60 to 64 years', 'concept': 'AGE AND SEX', 'predicateType': 'float' } expected['S0101_C02_015E'] = { 'label': 'Estimate!!Percent!!Total population!!AGE!!65 to 69 years', 'concept': 'AGE AND SEX', 'predicateType': 'float' } expected['S0101_C02_016E'] = { 'label': 'Estimate!!Percent!!Total population!!AGE!!70 to 74 years', 'concept': 'AGE AND SEX', 'predicateType': 'float' } expected['S0101_C02_017E'] = { 'label': 'Estimate!!Percent!!Total population!!AGE!!75 to 79 years', 'concept': 'AGE AND SEX', 'predicateType': 'float' } expected['S0101_C02_018E'] = { 'label': 'Estimate!!Percent!!Total population!!AGE!!80 to 84 years', 'concept': 'AGE AND SEX', 'predicateType': 'float' } expected['S0101_C02_019E'] = { 'label': 'Estimate!!Percent!!Total population!!AGE!!85 years and over', 'concept': 'AGE AND SEX', 'predicateType': 'float' } expected['S0101_C02_020E'] = { 'label': 'Estimate!!Percent!!Total population!!SELECTED AGE CATEGORIES!!5 to 14 years', 'concept': 'AGE AND SEX', 'predicateType': 'float' } expected['S0101_C02_021E'] = { 'label': 'Estimate!!Percent!!Total population!!SELECTED AGE CATEGORIES!!15 to 17 years', 'concept': 'AGE AND SEX', 'predicateType': 'float' } expected['S0101_C02_022E'] = { 'label': 'Estimate!!Percent!!Total population!!SELECTED AGE CATEGORIES!!Under 18 years', 'concept': 'AGE AND SEX', 'predicateType': 'float' } expected['S0101_C02_023E'] = { 'label': 'Estimate!!Percent!!Total population!!SELECTED AGE CATEGORIES!!18 to 24 years', 'concept': 'AGE AND SEX', 'predicateType': 'float' } expected['S0101_C02_024E'] = { 'label': 'Estimate!!Percent!!Total population!!SELECTED AGE CATEGORIES!!15 to 44 years', 'concept': 'AGE AND SEX', 'predicateType': 'float' } expected['S0101_C02_025E'] = { 'label': 'Estimate!!Percent!!Total population!!SELECTED AGE CATEGORIES!!16 years and over', 'concept': 'AGE AND SEX', 'predicateType': 'float' } expected['S0101_C02_026E'] = { 'label': 'Estimate!!Percent!!Total population!!SELECTED AGE CATEGORIES!!18 years and over', 'concept': 'AGE AND SEX', 'predicateType': 'float' } expected['S0101_C02_027E'] = { 'label': 'Estimate!!Percent!!Total population!!SELECTED AGE CATEGORIES!!21 years and over', 'concept': 'AGE AND SEX', 'predicateType': 'float' } expected['S0101_C02_028E'] = { 'label': 'Estimate!!Percent!!Total population!!SELECTED AGE CATEGORIES!!60 years and over', 'concept': 'AGE AND SEX', 'predicateType': 'float' } expected['S0101_C02_029E'] = { 'label': 'Estimate!!Percent!!Total population!!SELECTED AGE CATEGORIES!!62 years and over', 'concept': 'AGE AND SEX', 'predicateType': 'float' } expected['S0101_C02_030E'] = { 'label': 'Estimate!!Percent!!Total population!!SELECTED AGE CATEGORIES!!65 years and over', 'concept': 'AGE AND SEX', 'predicateType': 'float' } expected['S0101_C02_031E'] = { 'label': 'Estimate!!Percent!!Total population!!SELECTED AGE CATEGORIES!!75 years and over', 'concept': 'AGE AND SEX', 'predicateType': 'float' } expected['S0101_C02_032E'] = { 'label': 'Estimate!!Percent!!Total population!!SUMMARY INDICATORS!!Median age (years)', 'concept': 'AGE AND SEX', 'predicateType': 'int' } expected['S0101_C02_033E'] = { 'label': 'Estimate!!Percent!!Total population!!SUMMARY INDICATORS!!Sex ratio (males per 100 females)', 'concept': 'AGE AND SEX', 'predicateType': 'int' } expected['S0101_C02_034E'] = { 'label': 'Estimate!!Percent!!Total population!!SUMMARY INDICATORS!!Age dependency ratio', 'concept': 'AGE AND SEX', 'predicateType': 'int' } expected['S0101_C02_035E'] = { 'label': 'Estimate!!Percent!!Total population!!SUMMARY INDICATORS!!Old-age dependency ratio', 'concept': 'AGE AND SEX', 'predicateType': 'int' } expected['S0101_C02_036E'] = { 'label': 'Estimate!!Percent!!Total population!!SUMMARY INDICATORS!!Child dependency ratio', 'concept': 'AGE AND SEX', 'predicateType': 'int' } expected['S0101_C02_037E'] = { 'label': 'Estimate!!Percent!!Total population!!PERCENT ALLOCATED!!Sex', 'concept': 'AGE AND SEX', 'predicateType': 'float' } expected['S0101_C02_038E'] = { 'label': 'Estimate!!Percent!!Total population!!PERCENT ALLOCATED!!Age', 'concept': 'AGE AND SEX', 'predicateType': 'float' } self.assertEqual(censusdata.censustable('acs5', 2019, 'S0101_C02'), expected)
import censusdata pd.set_option('display.expand_frame_repr', False) pd.set_option('display.precision', 2) # sample = censusdata.search('acs5', 2015, 'concept', 'transportation')#[160:170] # # print(len(sample)) # # for item in sample: # print(item) censusdata.printtable(censusdata.censustable('acs5', 2015, 'B08301')) # # states = censusdata.geographies(censusdata.censusgeo([('state', '*')]), 'acs5', 2015) # # # counties = censusdata.geographies(censusdata.censusgeo([('state', '36'), ('county', '*')]), 'acs5', 2015) # # #print(counties) # # # data = censusdata.download('acs5', 2015, # # censusdata.censusgeo([('state', '36'), ('county', '081'), ('block group', '*')]), # # ['B23025_001E', 'B23025_002E', 'B23025_003E', 'B23025_004E', 'B23025_005E', # # 'B23025_006E', 'B23025_007E']) # data = censusdata.download('acs5', 2015, censusdata.censusgeo([('state', '36'), ('county', '*')]),