From 6e1247177bf1bc23d78dc1b28893af46ffca74a3 Mon Sep 17 00:00:00 2001 From: Felix Blanke Date: Fri, 1 Sep 2023 14:19:31 +0200 Subject: [PATCH] Remove NA entries from Bezirk table and show delta --- wsgi.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/wsgi.py b/wsgi.py index 634255f..1e05102 100644 --- a/wsgi.py +++ b/wsgi.py @@ -260,8 +260,9 @@ def convert_fig_to_svg(fig: plt.Figure) -> str: @app.route("/") @cache.cached(query_string=True) def tables(): - def _print_as_html(df: pd.DataFrame): + def _print_as_html(df: pd.DataFrame, total: int | None = None) -> None: df = df.astype({"Digitale Befragung": "Int32"}) + df = df.dropna() with pd.option_context("display.max_rows", None): table = df.to_html( index_names=False, @@ -281,9 +282,23 @@ def tables(): [ f" {df['Digitale Befragung'].sum()}", " ", - " ", ] ) + if total: + tfoot.extend([ + " ", + " Weitere Bezirke", + ]) + for i in range(len(df.columns) - 2): + tfoot.append(" ") + tfoot.extend( + [ + f" {total - df['Digitale Befragung'].sum()}", + " ", + ] + ) + tfoot.append(" ") + tfoot = "\n".join(tfoot) idx = table.index("") output_str.append(table[: idx - 1]) @@ -304,7 +319,7 @@ def tables(): plt.close() _print_as_html(df_state) - _print_as_html(df) + _print_as_html(df, total=df_state['Digitale Befragung'].sum()) return render_template( "base.html",