diff --git a/download_digital.py b/download_digital.py index e9f8afc..b3d36a5 100644 --- a/download_digital.py +++ b/download_digital.py @@ -76,6 +76,7 @@ def main( tag: str = "bez_data_2", dry_run: bool = False, grouped: bool = False, + html: bool = False, ) -> pd.DataFrame: r = requests.get(url) soup = BeautifulSoup(r.text, "html.parser") @@ -106,11 +107,51 @@ def main( data["Digitale Befragung"] = pd.Series(tot_col_data, index=tot_col_index) df = pd.DataFrame(data=data) if grouped: - df = df.groupby("Bundesland")[["Digitale Befragung"]].sum() - if dry_run: - df.loc["Total"] = df.sum(numeric_only=True) - with pd.option_context("display.max_rows", None): - print(df.astype({"Digitale Befragung": "Int32"})) + df = df.groupby("Bundesland", as_index=False)[["Digitale Befragung"]].sum() + + if dry_run or html: + if html: + print("") + print("") + + def _print_as_html(df: pd.DataFrame): + df = df.astype({"Digitale Befragung": "Int32"}) + with pd.option_context("display.max_rows", None): + if html: + table = df.to_html( + index_names=False, + justify="left", + index=False, + classes="sortable dataframe", + ) + + tfoot = [ + "
", + "