Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
spoonerf committed May 28, 2024
1 parent b911357 commit f51b077
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions etl/steps/data/garden/ihme_gbd/2024-05-20/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,33 @@ def add_regional_aggregates(
For Rate we need to calculate it for each region by dividing the sum of the 'Number' values by the sum of the population.
"""
# Split the table into Number, Percent and Rate
tb_number = tb[tb["metric"].isin(["Number", "Percent"])].copy()
tb_rate = tb[tb["metric"] == "Rate"].copy()
tb_percent = tb[tb["metric"] == "Percent"].copy()
# Add population data
tb_number = add_population(
df=tb_number, country_col="country", year_col="year", age_col="age", age_group_mapping=age_group_mapping
)
tb_rate = tb[tb["metric"] == "Rate"].copy()
tb_percent = tb[tb["metric"] == "Percent"].copy()
# Combine Number and Percent tables
tb_number_percent = pr.concat([tb_number, tb_percent], ignore_index=True)
# Add region aggregates - for Number
# Add region aggregates - for Number and Percent (if present)
tb_number_percent = geo.add_regions_to_table(
tb_number_percent,
index_columns=index_cols,
regions=regions,
ds_regions=ds_regions,
min_num_values_per_year=1,
)
# Add region aggregates - for Rate - only need population here?

# Calculate region aggregates - for Rate
tb_rate_regions = tb_number_percent[
(tb_number_percent["country"].isin(regions)) & (tb_number_percent["metric"] == "Number")
].copy()

# Calculate rates per 100,000 for regions
tb_rate_regions["value"] = tb_number["value"] / tb_number["population"] * 100_000
tb_rate_regions["metric"] = "Rate"

tb_rate = pr.concat([tb_rate, tb_rate_regions], ignore_index=True)
tb_rate = tb_rate.drop(columns="population")

Expand Down

0 comments on commit f51b077

Please sign in to comment.