Skip to content

Commit 84d5124

Browse files
Jingjing TangJingjing Tang
authored andcommitted
geo refactor
1 parent 4d180ac commit 84d5124

File tree

1 file changed

+7
-2
lines changed
  • nchs_mortality/delphi_nchs_mortality

1 file changed

+7
-2
lines changed

nchs_mortality/delphi_nchs_mortality/pull.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import numpy as np
44
import pandas as pd
55
from sodapy import Socrata
6+
from delphi_utils import GeoMapper
67

78
def pull_nchs_mortality_data(token: str, map_df: pd.DataFrame, test_mode: str):
89
"""Pull the latest NCHS Mortality data, and conforms it into a dataset.
@@ -91,7 +92,11 @@ def pull_nchs_mortality_data(token: str, map_df: pd.DataFrame, test_mode: str):
9192
)
9293

9394
# Add population info
95+
gmpr = GeoMapper()
9496
KEEP_COLUMNS.extend(["timestamp", "geo_id", "population"])
95-
df = df.merge(map_df, on="state")[KEEP_COLUMNS]
97+
df.rename({"state":"state_name"}, axis=1, inplace=True)
98+
df = gmpr.add_geocode(df, "state_name", "state_id")
99+
df = gmpr.add_population_column(df, "state_id")
100+
df.rename({"state_id":"geo_id"}, axis=1, inplace=True)
96101

97-
return df
102+
return df[KEEP_COLUMNS]

0 commit comments

Comments
 (0)