Skip to content

Commit

Permalink
add adult group
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasrodes committed Dec 11, 2024
1 parent 5140ea2 commit f73cda0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
18 changes: 18 additions & 0 deletions etl/steps/data/garden/demography/2024-12-06/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,24 @@ def add_dim_some_education(tb):
return tb


def add_dim_15plus(tb):
# Pivot table to have two columns: "0-14" and "total"
tb_adults = tb.loc[tb["age"].isin(["0-14", "total"])]
cols_index = ["country", "scenario", "sex", "education", "year"]
tb_adults = tb_adults.pivot(index=cols_index, columns="age", values="pop").reset_index()
# Fill with zero NAs of agr group "0-14". NAs mostly come from 'doesn't apply' (e.g. primary education for 0-14)
tb_adults["0-14"] = tb_adults["0-14"].fillna(0)
# Only estimate values for adults when "total" is not NA
tb_adults = tb_adults.dropna(subset=["total"])
# Estimate adults as "0-14" - 15+
tb_adults["15+"] = tb_adults["total"] - tb_adults["0-14"].fillna(0)
# Shape table
tb_adults = tb_adults.melt(id_vars=cols_index, value_name="pop", var_name="age")
# Concatenate with original table
tb = pr.concat([tb, tb_adults], ignore_index=True)
return tb


def get_index_columns(tb):
cols_index = list(tb.columns.intersection(COLUMNS_INDEX))
return cols_index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from etl.helpers import PathFinder, create_dataset

from .shared import add_dim_some_education, add_prop, make_table
from .shared import add_dim_15plus, add_dim_some_education, add_prop, make_table

# Get paths and naming conventions for current step.
paths = PathFinder(__file__)
Expand Down Expand Up @@ -105,6 +105,9 @@ def run(dest_dir: str) -> None:
# Add education="some_education" (only for sex=total and age=total, and indicator 'pop')
tb_sex_age_edu = add_dim_some_education(tb_sex_age_edu)

# Add 15+ age group
tb_sex_age_edu = add_dim_15plus(tb_sex_age_edu)

# Add population share
tb_sex_age_edu = add_prop(tb_sex_age_edu)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from etl.helpers import PathFinder, create_dataset

from .shared import add_dim_some_education, add_prop, make_table
from .shared import add_dim_15plus, add_dim_some_education, add_prop, make_table

# Get paths and naming conventions for current step.
paths = PathFinder(__file__)
Expand Down Expand Up @@ -105,6 +105,9 @@ def run(dest_dir: str) -> None:
# Add education="some_education" (only for sex=total and age=total, and indicator 'pop')
tb_sex_age_edu = add_dim_some_education(tb_sex_age_edu)

# Add 15+ age group
tb_sex_age_edu = add_dim_15plus(tb_sex_age_edu)

# Add population share
tb_sex_age_edu = add_prop(tb_sex_age_edu)

Expand Down

0 comments on commit f73cda0

Please sign in to comment.