Remove NA entries from Bezirk table and show delta

This commit is contained in:
Felix Blanke 2023-09-01 14:19:31 +02:00
parent 594ddbd740
commit 6e1247177b

21
wsgi.py
View File

@ -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" <td>{df['Digitale Befragung'].sum()}</td>",
" </tr>",
" </tfoot>",
]
)
if total:
tfoot.extend([
" <tr>",
" <td>Weitere Bezirke</td>",
])
for i in range(len(df.columns) - 2):
tfoot.append(" <td></td>")
tfoot.extend(
[
f" <td>{total - df['Digitale Befragung'].sum()}</td>",
" </tr>",
]
)
tfoot.append(" </tfoot>")
tfoot = "\n".join(tfoot)
idx = table.index("</table>")
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",