Skip to content
Extraits de code Groupes Projets
Valider ee5858a0 rédigé par Nicolas RAYMOND's avatar Nicolas RAYMOND
Parcourir les fichiers

Commentaire

parent 50c6dbd4
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -4,6 +4,9 @@ import pandas as pd ...@@ -4,6 +4,9 @@ import pandas as pd
import argparse import argparse
import os import os
################################################################################
# ArgsParser #
################################################################################
arg_parser = argparse.ArgumentParser( arg_parser = argparse.ArgumentParser(
description="Un simple script de convertion de relevé LCL pdf vers csv") description="Un simple script de convertion de relevé LCL pdf vers csv")
...@@ -21,27 +24,47 @@ args = arg_parser.parse_args() ...@@ -21,27 +24,47 @@ args = arg_parser.parse_args()
if args.out == "%path%.csv": if args.out == "%path%.csv":
args.out = os.path.splitext(args.path)[0]+'.csv' args.out = os.path.splitext(args.path)[0]+'.csv'
################################################################################
# Main #
################################################################################
print("Convertion de "+args.path+" vers "+args.out) print("Convertion de "+args.path+" vers "+args.out)
# Extait les tableaux présent dans le pdf en Dataframe pandas
tables = camelot.read_pdf(args.path, pages="1-end", flavor="stream") tables = camelot.read_pdf(args.path, pages="1-end", flavor="stream")
print("Total tables extracted:", tables.n) print("Nombre de tableau extrait: ", tables.n)
# Formatage du premier tableau (la ligne de titre)
# ------------------------------------------------
first_df = tables[1].df first_df = tables[1].df
first_df.iloc[1,1] = first_df.iloc[1,2] first_df.iloc[1,1] = first_df.iloc[1,2]
first_df.drop(2,inplace=True,axis=1) first_df.drop(2,inplace=True,axis=1)
first_df.columns = range(first_df.columns.size) first_df.columns = range(first_df.columns.size)
# Concatene tout les autres tableaux avec le premier formaté
# ----------------------------------------------------------
df_list = [first_df] df_list = [first_df]
if len(tables) > 2: if len(tables) > 2:
for table in tables[2:]: for table in tables[2:]:
df_list.append(table.df.iloc[2:]) df_list.append(table.df.iloc[2:])
r = pd.concat(df_list) r = pd.concat(df_list)
# Suppression des lignes LABELLE et REF si besoin
if not args.full_label :
r = r[r[0] != ""]
# Formatage du tableau final
# --------------------------
# Colonne VALEUR mise dans DATE (premiere col)
r.iloc[1:,0] = r.iloc[1:,2] r.iloc[1:,0] = r.iloc[1:,2]
# Formatage/Insertion des collones vides pour copier/coller direct
r[2] = "" r[2] = ""
r.insert(1,"","") r.insert(1,"","")
# Formatage des dates
r[0] = r[0].str.replace('.','/',regex=False) r[0] = r[0].str.replace('.','/',regex=False)
if not args.full_label :
r = r[r[0] != ""]
# Export en csv
r.to_csv(args.out, sep=";",index=False, header=False) r.to_csv(args.out, sep=";",index=False, header=False)
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter