policyengine-us icon indicating copy to clipboard operation
policyengine-us copied to clipboard

Modify county FIPS handling in `county` to use `pd.merge()` in place of `pd.loc()`

Open anth-volk opened this issue 1 year ago • 0 comments

Per commentary from Pavel:

We can use pd.merge() with how=left by creating two dataframes and joining them at the index - the benefit is more explicit handling of missing values (fills missing matched with Nan) - something like this:

input_df = pd.DataFrame({"county_fips": county_fips})
result_df = pd.merge(
    input_df,
    load_county_fips_dataset(),
    on="county_fips",
    how="left"
)
county_name = result_df["county_name"]
state_code = result_df["state"]

anth-volk avatar Apr 01 '25 18:04 anth-volk