Skip to content

Remove in-place modification of data frames in Safegraph processing. #420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 2, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions safegraph/delphi_safegraph/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,11 @@ def aggregate(df, signal_names, geo_resolution='county'):
"""
# Prepare geo resolution
if geo_resolution == 'county':
df['geo_id'] = df['county_fips']
geo_transformed_df = df.copy()
geo_transformed_df['geo_id'] = df['county_fips']
elif geo_resolution == 'state':
gmpr = GeoMapper()
df = gmpr.add_geocode(df,
geo_transformed_df = gmpr.add_geocode(df,
from_col='county_fips',
from_code='fips',
new_code='state_id',
Expand All @@ -136,7 +137,7 @@ def aggregate(df, signal_names, geo_resolution='county'):
f'`geo_resolution` must be one of {GEO_RESOLUTIONS}.')

# Aggregation and signal creation
grouped_df = df.groupby(['geo_id'])[signal_names]
grouped_df = geo_transformed_df.groupby(['geo_id'])[signal_names]
df_mean = grouped_df.mean()
df_sd = grouped_df.std()
df_n = grouped_df.count()
Expand Down