Skip to content
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

✨ microbe remove fill na #3698

Merged
merged 3 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 1 addition & 4 deletions etl/steps/data/garden/antibiotics/2024-12-02/microbe_amr.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Load a meadow dataset and create a garden dataset."""

import pandas as pd
from owid.catalog import Table

from etl.data_helpers import geo
Expand Down Expand Up @@ -35,9 +34,7 @@ def run(dest_dir: str) -> None:
)
tb_total = tb_total.rename(columns={"value": "total_deaths"}, errors="raise").drop(columns=["lower", "upper"])

tb = tb_amr.merge(tb_total, on=["country", "year", "infectious_syndrome"], how="right")
# Fill missing values with 0
tb["amr_attributable_deaths"] = tb["amr_attributable_deaths"].replace(pd.NA, 0)
tb = tb_amr.merge(tb_total, on=["country", "year", "infectious_syndrome"], how="inner")
tb["non_amr_attributable_deaths"] = tb["total_deaths"] - tb["amr_attributable_deaths"]
# Rename syndromes to be shorter for use in stacked bar charts
tb = rename_syndromes(tb)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""Load a meadow dataset and create a garden dataset."""
import pandas as pd

from etl.data_helpers import geo
from etl.helpers import PathFinder, create_dataset

Expand Down Expand Up @@ -39,9 +37,7 @@ def run(dest_dir: str) -> None:
)
tb_total = tb_total[tb_total["year"] == 2021]

tb = tb_amr.merge(tb_total, on=["country", "year", "pathogen"], how="right")
# Fill missing values with 0
tb["amr_attributable_deaths"] = tb["amr_attributable_deaths"].replace(pd.NA, 0)
tb = tb_amr.merge(tb_total, on=["country", "year", "pathogen"], how="inner")
tb["non_amr_attributable_deaths"] = tb["total_deaths"] - tb["amr_attributable_deaths"]

tb = geo.harmonize_countries(df=tb, countries_file=paths.country_mapping_path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ def run(dest_dir: str) -> None:
.rename(columns={"value": "total_deaths"})
)

tb = tb.merge(tb_total, on=["country", "year", "pathogen", "pathogen_type"], how="right")

tb["amr_attributable_deaths"] = tb["amr_attributable_deaths"].fillna(0)
tb = tb.merge(tb_total, on=["country", "year", "pathogen", "pathogen_type"], how="inner")
tb["non_amr_attributable_deaths"] = tb["total_deaths"] - tb["amr_attributable_deaths"]
# Process data.
tb = tb.drop(columns=["country", "pathogen_type"]).rename(columns={"pathogen": "country"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ def run(dest_dir: str) -> None:
countries_file=paths.country_mapping_path,
)

tb = tb.merge(tb_total, on=["country", "year", "pathogen", "pathogen_type"], how="right")

tb["amr_attributable_deaths"] = tb["amr_attributable_deaths"].fillna(0)
tb = tb.merge(tb_total, on=["country", "year", "pathogen", "pathogen_type"], how="inner")
tb["non_amr_attributable_deaths"] = tb["total_deaths"] - tb["amr_attributable_deaths"]
# Process data.
tb = tb.drop(columns=["country", "pathogen_type"]).rename(columns={"pathogen": "country"})
Expand Down
Loading