import csv
from collections import Counter
from pathlib import Path

by_period = {}
with Path(__file__).with_name("demo.csv").open(encoding="utf-8", newline="") as source:
    for row in csv.DictReader(source):
        counts = by_period.setdefault(row["period"], Counter())
        counts[row["category"]] += int(row["count"])

total = Counter()
print("対象月,受付件数,処理済み件数")
for period, counts in sorted(by_period.items()):
    print(f"{period},{counts['受付']},{counts['処理済み']}")
    total.update(counts)
print(f"全期間,{total['受付']},{total['処理済み']}")
