Feat: join excel files
This commit is contained in:
parent
9c06c64ae4
commit
687334f340
@ -3,6 +3,7 @@ from logging.config import dictConfig
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import click
|
import click
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
from .extract import extract_save
|
from .extract import extract_save
|
||||||
|
|
||||||
@ -62,5 +63,20 @@ def all(folder, dest):
|
|||||||
|
|
||||||
|
|
||||||
@main.command()
|
@main.command()
|
||||||
def join():
|
@click.option("--folder", help="Tous les fichiers dans folder", default="./")
|
||||||
pass
|
@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")
|
||||||
|
Loading…
Reference in New Issue
Block a user