Fix #3: replace empty string with np.nan #5

Merged
lafrite merged 1 commits from i3_valeurs_numeriques into main 2023-07-05 15:48:39 +00:00
2 changed files with 7 additions and 4 deletions

View File

@ -83,6 +83,5 @@ def table2df(tables):
df = pd.concat(dfs) df = pd.concat(dfs)
df["immeuble"] = df["immeuble"].apply(lambda x: x[0].capitalize()) df["immeuble"] = df["immeuble"].apply(lambda x: x[0].capitalize())
print(df.columns)
df["lot"] = df["RECAPITULATIF DES OPERATIONS"].apply(get_lot) df["lot"] = df["RECAPITULATIF DES OPERATIONS"].apply(get_lot)
return df.astype(DF_TYPES, errors="ignore") return df.astype(DF_TYPES)

View File

@ -1,3 +1,4 @@
import numpy as np
import pandas as pd import pandas as pd
DF_TYPES = { DF_TYPES = {
@ -33,7 +34,7 @@ def is_drop(row):
def extract(table, additionnal_fields: dict = {}): def extract(table, additionnal_fields: dict = {}):
"""Turn table to dictionary with additionnal fields""" """Turn table to dictionary with additional fields"""
extracted = [] extracted = []
header = table[0] header = table[0]
for row in table[1:]: for row in table[1:]:
@ -159,4 +160,7 @@ def table2df(tables):
df["immeuble"] = df["immeuble"].apply(lambda x: x[0].capitalize()) df["immeuble"] = df["immeuble"].apply(lambda x: x[0].capitalize())
df["Type"] = df["Type"].apply(clean_type) df["Type"] = df["Type"].apply(clean_type)
return df.astype(DF_TYPES, errors="ignore") numeric_cols = [k for k, v in DF_TYPES.items() if v == float]
df[numeric_cols] = df[numeric_cols].replace("", np.nan)
return df.astype(DF_TYPES)