Infer Bezirk value from total if only one entry is missing

This commit is contained in:
Felix Blanke 2023-09-14 11:05:57 +02:00
parent 14e314822d
commit 13d47be9c1

View File

@ -292,8 +292,16 @@ def _print_as_html(
) -> list[str]:
df = df.astype({"Digitale Befragung": "Int32"})
num_missing = (df[df.isna().any(axis=1)]["Landesbezirk"] != "Hessen").sum()
if num_missing == 1:
# infer value from total
df_tmp = df.loc[df["Landesbezirk"] != "Hessen"]
idx = df_tmp.loc[df_tmp.isna().any(axis=1)].iloc[0].name
df["Digitale Befragung"].loc[idx] = (
total - df.dropna()["Digitale Befragung"].sum()
)
if dropna:
df = df.dropna()
with pd.option_context("display.max_rows", None):
table = df.to_html(
index_names=False,