-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconvert_ODMS_file_to_timeseries.py
41 lines (28 loc) · 1.66 KB
/
convert_ODMS_file_to_timeseries.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
import pandas
import glob
import urllib.request
url = 'http://example.com/'
open_data_ms = pandas.read_csv(urllib.request.urlopen("https://raw.githubusercontent.com/od-ms/resources/master/coronavirus-fallzahlen-regierungsbezirk-muenster.csv"))
open_data_ms['Datum'] = pandas.to_datetime(open_data_ms['Datum'], format='%d.%m.%Y')
open_data_ms = open_data_ms.sort_values(by='Datum')
confirmed_df = pandas.DataFrame({'Kommune': open_data_ms['Gebiet'].unique()})
recovered_df = pandas.DataFrame({'Kommune': open_data_ms['Gebiet'].unique()})
deaths_df = pandas.DataFrame({'Kommune': open_data_ms['Gebiet'].unique()})
confirmed_df = confirmed_df.set_index(['Kommune'], drop=True)
recovered_df = recovered_df.set_index(['Kommune'], drop=True)
deaths_df = deaths_df.set_index(['Kommune'], drop=True)
for day in open_data_ms['Datum'].dt.date.unique():
for kommune in open_data_ms['Gebiet'].unique():
all_data_kommune = open_data_ms[open_data_ms['Gebiet'] == kommune]
c = all_data_kommune[all_data_kommune['Datum'] == pandas.Timestamp(day)]['Bestätigte Faelle'].values
r = all_data_kommune[all_data_kommune['Datum'] == pandas.Timestamp(day)]['Gesundete'].values
d = all_data_kommune[all_data_kommune['Datum'] == pandas.Timestamp(day)]['Todesfaelle'].values
if len(c) == 1:
confirmed_df.loc[kommune, day] = c
if len(r) == 1:
recovered_df.loc[kommune, day] = r
if len(d) == 1:
deaths_df.loc[kommune, day] = d
confirmed_df.to_csv("data/time_series/time_series_covid-19_nrw_confirmed.csv")
recovered_df.to_csv("data/time_series/time_series_covid-19_nrw_recovered.csv")
deaths_df.to_csv("data/time_series/time_series_covid-19_nrw_deaths.csv")