From 21869e0f843b86a169bbc8e146668c8cc8d78257 Mon Sep 17 00:00:00 2001 From: owidbot Date: Thu, 28 Nov 2024 16:56:23 +0000 Subject: [PATCH] fasttrack: fasttrack/latest/lives_saved_vaccination_who.csv --- .../latest/lives_saved_vaccination_who.py | 20 ++++++++++++++++++- .../lives_saved_vaccination_who.csv.dvc | 6 +++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/etl/steps/data/grapher/fasttrack/latest/lives_saved_vaccination_who.py b/etl/steps/data/grapher/fasttrack/latest/lives_saved_vaccination_who.py index 17ec65f21ba..3fcf6026ee9 100644 --- a/etl/steps/data/grapher/fasttrack/latest/lives_saved_vaccination_who.py +++ b/etl/steps/data/grapher/fasttrack/latest/lives_saved_vaccination_who.py @@ -1,3 +1,5 @@ +import pandas as pd + from etl.helpers import PathFinder, create_dataset, get_metadata_path from etl.snapshot import Snapshot @@ -11,8 +13,20 @@ def run(dest_dir: str) -> None: # load data tb = snap.read_csv() + # add dimensions with dim_ prefix + dims = [c for c in tb.columns if c.startswith("dim_")] + dims_without_prefix = [c[4:] for c in dims] + + if dims: + tb = tb.rename(columns={d: dw for d, dw in zip(dims, dims_without_prefix)}) + + if uses_dates(tb["year"]): + tb = tb.rename(columns={"year": "date"}).format(["country", "date"] + dims_without_prefix) + else: + tb = tb.format(["country", "year"] + dims_without_prefix) + # add table, update metadata from *.meta.yml and save - ds = create_dataset(dest_dir, tables=[tb.set_index(["country", "year"])], default_metadata=snap.metadata) + ds = create_dataset(dest_dir, tables=[tb], default_metadata=snap.metadata) # override metadata if necessary meta_path = get_metadata_path(dest_dir).with_suffix(".override.yml") @@ -20,3 +34,7 @@ def run(dest_dir: str) -> None: ds.update_metadata(meta_path) ds.save() + + +def uses_dates(s: pd.Series) -> bool: + return pd.to_datetime(s, errors="coerce", format="%Y-%m-%d").notnull().all() diff --git a/snapshots/fasttrack/latest/lives_saved_vaccination_who.csv.dvc b/snapshots/fasttrack/latest/lives_saved_vaccination_who.csv.dvc index aa7be1be0f4..0a344e05f02 100644 --- a/snapshots/fasttrack/latest/lives_saved_vaccination_who.csv.dvc +++ b/snapshots/fasttrack/latest/lives_saved_vaccination_who.csv.dvc @@ -1,14 +1,14 @@ meta: origin: producer: |- - Shattock et al. (2024). Contribution of vaccination to improved child survival: modelling 50 years of the Expanded Programme on Immunization. + Shattock et al. (2024). Contribution of vaccination to improved survival and health: modelling 50 years of the Expanded Programme on Immunization. title: lives_saved_vaccination_who citation_full: |- - Shattock et al. (2024). Contribution of vaccination to improved child survival: modelling 50 years of the Expanded Programme on Immunization. The Lancet. + Shattock et al. (2024). Contribution of vaccination to improved survival and health: modelling 50 years of the Expanded Programme on Immunization. The Lancet. url_main: https://www.thelancet.com/journals/lancet/article/PIIS0140-6736(24)00850-X/fulltext url_download: |- https://docs.google.com/spreadsheets/d/e/2PACX-1vSP20L-mjOB7xZ73EGhXyjZSdC_CBwWZAKkCs_T4iCRgwXKNXBb0K2H8L8mI7rnLIol8MqYAyG5YMHq/pub?output=csv - date_accessed: '2024-05-03' + date_accessed: '2024-11-28' name: Lives saved by vaccinations (WHO, 2024) description: Estimates of the number of lives saved by vaccination over the last 50 years (from 1974 to 2024). license: {}