@@ -71,11 +71,11 @@ def county_to_state(self, data):
71
71
converters = {"fips" : GeoMaps .convert_fips },
72
72
)
73
73
state_map .drop_duplicates (inplace = True )
74
- data = data . merge (
75
- state_map , how = "left" , left_on = "PatCountyFIPS" , right_on = "fips"
76
- )
77
- data . dropna ( inplace = True )
78
- data .drop (columns = [ "PatCountyFIPS" , "fips" ] , inplace = True )
74
+ data = self . gmpr . add_geocode ( data ,
75
+ "fips" ,
76
+ "state_id" ,
77
+ from_col = "PatCountyFIPS" )
78
+ data .drop (columns = "PatCountyFIPS" , inplace = True )
79
79
data = data .groupby (["ServiceDate" , "state_id" ]).sum ().reset_index ()
80
80
81
81
return data .groupby ("state_id" ), "state_id"
@@ -109,15 +109,15 @@ def county_to_hrr(self, data):
109
109
110
110
hrr_map = hrr_map .melt (["fips" ], var_name = "hrr" , value_name = "wpop" )
111
111
hrr_map = hrr_map [hrr_map ["wpop" ] > 0 ]
112
-
113
- data = data . merge ( hrr_map , how = "left" , left_on = "PatCountyFIPS" , right_on = "fips" )
114
- ## drops rows with no matching HRR, which should not be many
115
- data . dropna ( inplace = True )
116
- data .drop (columns = [ "PatCountyFIPS" , "fips" ] , inplace = True )
112
+ data = self . gmpr . add_geocode ( data ,
113
+ "fips" ,
114
+ "hrr" ,
115
+ from_col = "PatCountyFIPS" )
116
+ data .drop (columns = "PatCountyFIPS" , inplace = True )
117
117
118
118
## do a weighted sum by the wpop column to get each HRR's contribution
119
119
tmp = data .groupby (["ServiceDate" , "hrr" ])
120
- wtsum = lambda g : g ["wpop " ].values @ g [Config .COUNT_COLS ]
120
+ wtsum = lambda g : g ["weight " ].values @ g [Config .COUNT_COLS ]
121
121
data = tmp .apply (wtsum ).reset_index ()
122
122
123
123
return data .groupby ("hrr" ), "hrr"
0 commit comments