From bd866dda36120edcd72d0e7f4ed1c967c21028ca Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Sat, 2 Mar 2024 18:32:06 +0100 Subject: [PATCH] Feat: isolate category replacements --- scripts/history_stagging.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/scripts/history_stagging.py b/scripts/history_stagging.py index b1fc422..77d88a9 100644 --- a/scripts/history_stagging.py +++ b/scripts/history_stagging.py @@ -78,8 +78,7 @@ def crg(history_path: Path, staging_path: Path, metadatas: dict, writing_func=to return wrote_files -def trans_2017_2021(dfs, **kwrds): - df, cat = dfs +def extract_cat(cat): cat_drop = list(cat[cat["Nouvelles"] == "NE PAS IMPORTER"]["Anciennes"]) cat_trans = cat[cat["Nouvelles"] != "NE PAS IMPORTER"] @@ -87,6 +86,13 @@ def trans_2017_2021(dfs, **kwrds): for _, (old, new) in cat_trans.iterrows(): trans[old] = new + return trans, cat_drop + + +def trans_2017_2021(dfs, **kwrds): + df, cat = dfs + cat_trans, cat_drop = extract_cat(cat) + df = df[~df["Categorie"].isin(cat_drop)] df = df.assign( @@ -97,7 +103,7 @@ def trans_2017_2021(dfs, **kwrds): Lot=df["immeuble"].astype(str) + df["porte"].astype("str").str.zfill(2), Année=df["Date"].astype(str).str.slice(0, 4), Mois=df["Date"].astype(str).str.slice(5, 7), - Catégorie=df["Categorie"].replace(trans), + Catégorie=df["Categorie"].replace(cat_trans), Fournisseur="", )