From 687334f3400f5b8279688adf1254351120ce9413 Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Wed, 28 Sep 2022 16:47:22 +0200 Subject: [PATCH] Feat: join excel files --- pdf_oralia/scripts.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/pdf_oralia/scripts.py b/pdf_oralia/scripts.py index b73d284..875875f 100644 --- a/pdf_oralia/scripts.py +++ b/pdf_oralia/scripts.py @@ -3,6 +3,7 @@ from logging.config import dictConfig from pathlib import Path import click +import pandas as pd from .extract import extract_save @@ -62,5 +63,20 @@ def all(folder, dest): @main.command() -def join(): - pass +@click.option("--folder", help="Tous les fichiers dans folder", default="./") +@click.option("--dest", help="Où mettre les fichiers produits", default="") +def join(folder, dest): + p = Path(folder) + dfs = { + "charge": [], + "locataire": [], + } + for file in p.glob("*.xlsx"): + year, month, immeuble, table = file.stem.split("_") + df = pd.read_excel(file).assign(annee=year, mois=month, immeuble=immeuble) + dfs[table].append(df) + for tablename, datas in dfs.items(): + df = pd.concat(datas) + destination = Path(dest) / f"{tablename}.xlsx" + df.to_excel(destination, index=False) + logging.info(f"{destination} written")