33
33
FIPS_PUERTO_RICO_POPULATION_URL = "https://www2.census.gov/geo/docs/maps-data/data/rel/zcta_county_rel_10.txt?"
34
34
STATE_HHS_FILE = "hhs.txt"
35
35
ZIP_POP_MISSING_FILE = "zip_pop_filling.csv"
36
- LOWPOP_COUNTY_GROUPS_FILE = "lowpop_county_groups .csv"
36
+ CHNG_COUNTY_GROUPS_FILE = "chng_county_groups .csv"
37
37
38
38
# Out files
39
39
FIPS_STATE_OUT_FILENAME = "fips_state_table.csv"
@@ -484,7 +484,7 @@ def derive_fips_chngfips_crosswalk():
484
484
derive_fips_state_crosswalk ()
485
485
486
486
assign_county_groups ()
487
- county_groups = pd .read_csv (LOWPOP_COUNTY_GROUPS_FILE , dtype = "string" , index_col = False )
487
+ county_groups = pd .read_csv (CHNG_COUNTY_GROUPS_FILE , dtype = "string" , index_col = False )
488
488
# Split list of county FIPS codes into separate columns.
489
489
county_groups = pd .concat (
490
490
[county_groups , county_groups .fips_list .str .split ("|" , expand = True )],
@@ -503,21 +503,21 @@ def derive_fips_chngfips_crosswalk():
503
503
columns = "county_num"
504
504
).dropna ()
505
505
506
- county_groups ["state_fips" ] = county_groups ["state_fips" ].str .zfill (2 ). astype ( "string" )
507
- county_groups ["group" ] = county_groups ["group" ].str .zfill (2 ). astype ( "string" )
506
+ county_groups ["state_fips" ] = county_groups ["state_fips" ].str .zfill (2 )
507
+ county_groups ["group" ] = county_groups ["group" ].str .zfill (2 )
508
508
county_groups ["fips" ] = county_groups ["fips" ].str .zfill (5 ).astype ("string" )
509
509
# Combine state codes and group ids into a single FIPS code.
510
510
county_groups ["chng-fips" ] = county_groups ["state_fips" ] + "g" + county_groups ["group" ]
511
511
512
512
county_groups = county_groups [["fips" , "chng-fips" ]]
513
513
fips_to_state = pd .read_csv (join (OUTPUT_DIR , FIPS_STATE_OUT_FILENAME ), dtype = "string" , index_col = False )
514
514
515
- # Get all the fips that aren't included in the low-population groupings.
515
+ # Get all the fips that aren't included in the chng groupings.
516
516
extra_fips_list = list (set (fips_to_state .fips ) - set (county_groups .fips ))
517
- # Normal fips codes and CHNG fips codes are the same for high-population counties.
517
+ # Normal fips codes and CHNG fips codes are the same for ungrouped counties.
518
518
extra_fips_df = pd .DataFrame ({"fips" : extra_fips_list , "chng-fips" : extra_fips_list }, dtype = "string" )
519
519
520
- # Combine high-pop and low-pop counties.
520
+ # Combine grouped and ungrouped counties.
521
521
pd .concat (
522
522
[county_groups , extra_fips_df ]
523
523
).sort_values (
@@ -581,12 +581,12 @@ def fetch_county_groups_spreadsheet():
581
581
def assign_county_groups ():
582
582
county_groups = fetch_county_groups_spreadsheet ()
583
583
584
- # If a `lowpop_county_groups.csv` already exists in `data_proc/geomap`, we
584
+ # If a county groups mapping file already exists in `data_proc/geomap`, we
585
585
# have to be careful to not reassign a group number to a different group.
586
586
# Group numbers must remain fixed, even if a given county group is no longer
587
587
# being used.
588
- if isfile (LOWPOP_COUNTY_GROUPS_FILE ):
589
- old_county_groups = pd .read_csv (LOWPOP_COUNTY_GROUPS_FILE , dtype = "string" , index_col = False )
588
+ if isfile (CHNG_COUNTY_GROUPS_FILE ):
589
+ old_county_groups = pd .read_csv (CHNG_COUNTY_GROUPS_FILE , dtype = "string" , index_col = False )
590
590
old_county_groups .group = old_county_groups .group .astype (int )
591
591
old_county_groups .state_fips = old_county_groups .state_fips .astype (int )
592
592
@@ -636,12 +636,13 @@ def assign_county_groups():
636
636
# Combine old_county_groups and county_groups
637
637
county_groups = pd .concat ([old_county_groups , county_groups ])
638
638
else :
639
+ # Group numbers are 1-indexed.
639
640
county_groups ["group" ] = county_groups .groupby ("state_fips" ).cumcount () + 1
640
641
641
642
county_groups .sort_values (
642
643
["state_fips" ], kind = "stable"
643
644
).to_csv (
644
- LOWPOP_COUNTY_GROUPS_FILE , index = False
645
+ CHNG_COUNTY_GROUPS_FILE , index = False
645
646
)
646
647
647
648
0 commit comments