Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasrodes committed Dec 11, 2024
1 parent f73cda0 commit c4eae16
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions etl/steps/data/garden/demography/2024-12-06/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,21 @@ def add_dim_some_education(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"])]
tb_adults = tb.loc[tb["age"].isin(["0-4", "5-9", "10-14", "total"]) & (tb["education"] != "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)
# 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["15+"] = (
tb_adults["total"] - tb_adults["0-4"].fillna(0) - tb_adults["5-9"].fillna(0) - tb_adults["10-14"].fillna(0)
)
# Drop columns
tb_adults = tb_adults.drop(columns=["0-4", "5-9", "10-14", "total"])
# Replace negative values for zero
flag = tb_adults["15+"] < 0
tb_adults.loc[flag, "15+"] = 0
# Shape table
tb_adults = tb_adults.melt(id_vars=cols_index, value_name="pop", var_name="age")
# Concatenate with original table
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_15plus, 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

0 comments on commit c4eae16

Please sign in to comment.