愛知県内の感染者・検査件数

import datetime
import pathlib
import re

import pandas as pd

def str2date(s):

    y = datetime.date.today().year
    m, d = map(int, re.findall("\d{1,2}", s.split("~")[-1].strip()))
    return pd.Timestamp(y, m, d)

df = pd.read_html("https://www.pref.aichi.jp/site/covid19-aichi/kansensya-kensa.html", match="検査日", na_values="-")[0].iloc[:-1]

df["備考"] = df["検査日"]

df.loc[df["検査日"].str.contains("~"), "合算"] = "○"

df["検査日"] = df["検査日"].apply(str2date)

p = pathlib.Path("data", "inspections_summary.csv")
p.parent.mkdir(parents=True, exist_ok=True)

df.to_csv(p, index=False, header=True)