Example #1
0
# loop through the tracts, getting the data for each and appending to the dataframes
all_counties=list(set([f['properties']['COUNTY'] for f in all_zones['features']]))
h_acs=pd.DataFrame()
p_acs=pd.DataFrame()

for county in all_counties:
    print(county)
    h_acs_c = c.block_group_and_tract_query(block_group_columns,
                    tract_columns, state, county, 
                    merge_columns=['tract', 'county', 'state'],
                    block_group_size_attr="B11001_001E",
                    tract_size_attr="B08201_001E",
                    tract=None, year=2017)
    h_acs=pd.concat([h_acs, h_acs_c])
    p_acs_c = c.block_group_query(all_columns, state, county, tract=None, year=2017)
    p_acs=pd.concat([p_acs, p_acs_c])
h_acs=h_acs.reset_index(drop=True)
p_acs=p_acs.reset_index(drop=True)

# add puma information to the dataframes
h_acs['puma'] = h_acs.apply(lambda row: c.tract_to_puma(row['state'], row['county'], row['tract'])[0], axis=1)
p_acs['puma'] = p_acs.apply(lambda row: c.tract_to_puma(row['state'], row['county'], row['tract'])[0], axis=1)


# Since we queried by county, some of the block_groups may not be in our study area
# remove any entries not in those block groups
all_block_group_ids=list(set([f['properties']['TRACT']+'_'+ 
                              f['properties']['BLKGRP']
                              for f in all_zones['features']]))
h_acs['block_group_id']=h_acs.apply(lambda row: