Skip to content

Commit 0ef6b13

Browse files
committed
split out single counties from fips_list field
We can't rely on the component counties of a group being listed individually, so reconstruct those fields ourselves based on the concatenated `fips_list` field. Split by the separator (pipe `|`) and save each result to a new column.
1 parent 18a08a5 commit 0ef6b13

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

_delphi_utils_python/data_proc/geomap/geo_data_proc.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,14 @@ def derive_fips_chngfips_crosswalk():
484484
derive_fips_state_crosswalk()
485485

486486
assign_county_groups()
487-
county_groups = pd.read_csv(LOWPOP_COUNTY_GROUPS_FILE, dtype="string", index_col=False
488-
).drop(columns = "fips_list")
487+
county_groups = pd.read_csv(LOWPOP_COUNTY_GROUPS_FILE, dtype="string", index_col=False)
488+
# Split list of county FIPS codes into separate columns.
489+
county_groups = pd.concat(
490+
[county_groups, county_groups.fips_list.str.split("|", expand=True)],
491+
axis=1
492+
).drop(
493+
columns = "fips_list"
494+
)
489495

490496
# Change to long format.
491497
county_groups = pd.melt(

0 commit comments

Comments
 (0)