-
Notifications
You must be signed in to change notification settings - Fork 16
/
consolidate_germany.py
executable file
·54 lines (48 loc) · 1.32 KB
/
consolidate_germany.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import csv
fields = [
"confirmed",
"deceased",
"recovered"
]
bundeslanders = [
"Baden-Württemberg",
"Bayern",
"Berlin",
"Brandenburg",
"Bremen",
"Hamburg",
"Hessen",
"Mecklenburg-Vorpommern",
"Niedersachsen",
"Nordrhein-Westfalen",
"Rheinland-Pfalz",
"Saarland",
"Sachsen",
"Sachsen-Anhalt",
"Schleswig-Holstein",
"Thüringen"
]
data = {}
mapping = {
"AnzahlFall": "confirmed",
"AnzahlTodesfall": "deceased",
"AnzahlGenesen": "recovered"
}
with open(os.path.join("data", "covid-germany-landkreisen.csv")) as f:
for row in csv.DictReader(f):
dat = row["Meldedatum"].split(" ")[0].replace("/", "-")
if dat not in data:
data[dat] = {k: {"confirmed": 0, "deceased": 0, "recovered": 0} for k in bundeslanders}
bdl = row["Bundesland"]
for k, f in mapping.items():
data[dat][bdl][f] += int(row[k])
lastvals = {k: {"confirmed": 0, "deceased": 0, "recovered": 0} for k in bundeslanders}
print("date,bundeslander," + ",".join(fields))
for d in sorted(data.keys()):
for c in sorted(bundeslanders):
for k in fields:
lastvals[c][k] += data[d][c].get(k, 0)
print(",".join([d, c] + [str(lastvals[c][k]) for k in fields]))