|
12 | 12 | from os import remove, listdir
|
13 | 13 | from os.path import join, isfile
|
14 | 14 | from zipfile import ZipFile
|
15 |
| -from pandas.core.frame import DataFrame |
16 | 15 |
|
17 | 16 | import requests
|
18 | 17 | import pandas as pd
|
@@ -70,8 +69,8 @@ def create_fips_zip_crosswalk():
|
70 | 69 | # Find the population fractions (the heaviest computation, takes about a minute)
|
71 | 70 | # Note that the denominator in the fractions is the source population
|
72 | 71 | pop_df.set_index(["fips", "zip"], inplace=True)
|
73 |
| - fips_zip: DataFrame = pop_df.groupby("fips", as_index=False).apply(lambda g: g["pop"] / g["pop"].sum()) |
74 |
| - zip_fips: DataFrame = pop_df.groupby("zip", as_index=False).apply(lambda g: g["pop"] / g["pop"].sum()) |
| 72 | + fips_zip: pd.DataFrame = pop_df.groupby("fips", as_index=False).apply(lambda g: g["pop"] / g["pop"].sum()) |
| 73 | + zip_fips: pd.DataFrame = pop_df.groupby("zip", as_index=False).apply(lambda g: g["pop"] / g["pop"].sum()) |
75 | 74 |
|
76 | 75 | # Rename and write to file
|
77 | 76 | fips_zip = fips_zip.reset_index(level=["fips", "zip"]).rename(columns={"pop": "weight"}).query("weight > 0.0")
|
@@ -228,7 +227,7 @@ def create_state_population_table():
|
228 | 227 | derive_fips_state_crosswalk()
|
229 | 228 |
|
230 | 229 | census_pop = pd.read_csv(join(OUTPUT_DIR, FIPS_POPULATION_OUT_FILENAME), dtype={"fips": str, "pop": int})
|
231 |
| - state: DataFrame = pd.read_csv(join(OUTPUT_DIR, FIPS_STATE_OUT_FILENAME), dtype=str) |
| 230 | + state: pd.DataFrame = pd.read_csv(join(OUTPUT_DIR, FIPS_STATE_OUT_FILENAME), dtype=str) |
232 | 231 | state_pop = state.merge(census_pop, on="fips").groupby(["state_code", "state_id", "state_name"], as_index=False).sum()
|
233 | 232 | state_pop.sort_values("state_code").to_csv(join(OUTPUT_DIR, STATE_POPULATION_OUT_FILENAME), index=False)
|
234 | 233 |
|
|
0 commit comments