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: row['tract']+'_'+row['block group'], axis=1) p_acs['block_group_id']=p_acs.apply(lambda row: row['tract']+'_'+row['block group'], axis=1) h_acs=h_acs.loc[h_acs['block_group_id'].isin(all_block_group_ids)] p_acs=p_acs.loc[p_acs['block_group_id'].isin(all_block_group_ids)] # =============================================================================