Feat: set type for columns

This commit is contained in:
Bertrand Benjamin 2022-09-27 21:14:27 +02:00
parent da53656609
commit 020e9195b1
3 changed files with 28 additions and 3 deletions

View File

@ -32,8 +32,8 @@ def extract_from_pdf(pdf, charge_dest, location_dest):
df_charge.to_excel(charge_dest, sheet_name="Charges", index=False) df_charge.to_excel(charge_dest, sheet_name="Charges", index=False)
print(f"{charge_dest} saved") print(f"{charge_dest} saved")
df_loc = extract_situation_loc(loc_table) df_loc = extract_situation_loc(loc_table, mois=mois, annee=annee)
df_loc = df_loc.assign(mois=mois, annee=annee) df_loc = df_loc.assign()
df_loc.to_excel(location_dest, sheet_name="Location", index=False) df_loc.to_excel(location_dest, sheet_name="Location", index=False)
print(f"{location_dest} saved") print(f"{location_dest} saved")

View File

@ -8,10 +8,20 @@ def extract_charge(table):
pd.DataFrame(table[1:], columns=table[0]) pd.DataFrame(table[1:], columns=table[0])
.replace("", np.nan) .replace("", np.nan)
.dropna(subset=["Débits"]) .dropna(subset=["Débits"])
.astype(
{
"Débits": "float64",
"Crédits": "float64",
"Dont T.V.A.": "float64",
"Locatif": "float64",
"Déductible": "float64",
}
)
) )
drop_index = df[ drop_index = df[
df["RECAPITULATIF DES OPERATIONS"].str.contains("TOTAUX", case=False) df["RECAPITULATIF DES OPERATIONS"].str.contains("TOTAUX", case=False)
| df["RECAPITULATIF DES OPERATIONS"].str.contains("solde", case=False) | df["RECAPITULATIF DES OPERATIONS"].str.contains("solde", case=False)
].index ].index
df.drop(drop_index, inplace=True) df.drop(drop_index, inplace=True)
return df return df

View File

@ -18,7 +18,7 @@ def parse_above_loc(content):
return pd.Series(row) return pd.Series(row)
def extract_situation_loc(table): def extract_situation_loc(table, mois, annee):
"""From pdfplumber table extract locataire df""" """From pdfplumber table extract locataire df"""
try: try:
df = pd.DataFrame(table[1:], columns=table[0]) df = pd.DataFrame(table[1:], columns=table[0])
@ -37,4 +37,19 @@ def extract_situation_loc(table):
rows.append(up_row) rows.append(up_row)
df_cleaned = pd.concat(rows, axis=1).T df_cleaned = pd.concat(rows, axis=1).T
df_cleaned.drop(["Locataires", "", "Période"], axis=1, inplace=True) df_cleaned.drop(["Locataires", "", "Période"], axis=1, inplace=True)
df_cleaned = df_cleaned.astype(
{
"Loyers": "float64",
"Taxes": "float64",
"Provisions": "float64",
"Divers": "float64",
"Total": "float64",
"Réglés": "float64",
"Impayés": "float64",
},
errors="ignore",
)
df_cleaned = df_cleaned.assign(mois=mois, annee=annee)
return df_cleaned return df_cleaned