COVID-19 Ländervergleich
Ingo Dahn (dahn@dahn-research.eu)
Mit diesem Notebook kann man die Entwicklung der COVID-19-Daten (Infizierte und Verstorbene) in zwei Ländern vergleichen. Diese Seite wird unter der Creative Commons Lizenz CC BY-NC-SA 4.0 veröffentlicht.
Die Daten werden von https://opendata.ecdc.europa.eu/covid19/casedistribution/csv geladen und sind so stets aktuell.
import pandas as pd
url="https://opendata.ecdc.europa.eu/covid19/nationalcasedeath/csv"
data=pd.read_csv(url)
dataV=data.values
dataT=data.T
dataTV=dataT.values
regions=sorted(set(dataTV[2]))
dataD={}
for n in range(0,len(dataV)):
line=dataV[n]
region=line[2];country=line[0];date=line[6]; cases=line[4]; deaths=line[5]; population=line[3]
if country == 'Cura\xc3\xa7ao':
country='Curacao'
if region == 'Other' or population == 'nan':
next
if not region in dataD.keys():
dataD[region]={}
if not country in dataD[region].keys():
dataD[region][country]={'population': population, 'cases':[],'deaths':[]}
if line[4] == 'cases':
dataD[region][country]['cases'].append((date,line[5]))
if line[4] == 'deaths':
dataD[region][country]['deaths'].append((date,line[5]))
defaultCountries={'Europe': 'Germany', 'America': 'America (total)','Asia': 'China', 'Africa':'South_Africa', 'Oceania': 'Australia'}
datesAll=[ dc[0] for dc in dataD['Europe']['Germany']['cases'] ]
dataNr=len(datesAll)
style = """
<style type="text/css">
.sagecell_interactContainer{border: none; margin: 0px; padding: 0px}
.sagecell_interactControlLabel{min-width: 8ex; text-align: left !important}
.sagecell_interactOutput{padding: 0px}
</style>
"""
show(html(style))
show(html(u"Daten von Woche %s bis Woche %s geladen"%(datesAll[0],datesAll[dataNr-1])))
datesMap={}
for n in range(0,dataNr):
datesMap[datesAll[n]]=n
regions=sorted(defaultCountries.keys())
def setDates(Data):
LL=[0 for n in range(0,dataNr)]
for i in range(0,len(Data)):
LL[datesMap[Data[i][0]]]=Data[i][1]
return LL
def cumulateList(L):
LL=[];s=0;
for i in range(0,len(L)):
s += L[i]
LL.append(s)
return LL
def normListPer(L,Ord,Pop):
po=Ord/Pop
return [n*po for n in L]
def cumulatedNormed(L,c,n,P):
casePlotData0=L
if c:
casePlotData1=cumulateList(L)
else:
casePlotData1=casePlotData0
if n:
casePlotData=normListPer(casePlotData1,10^5,P)
else:
casePlotData=casePlotData1
return casePlotData
region_1='Europe';country_1='Germany'
region_2='America'; country_2='America (total)'
@interact
def panel_11(region_1s=selector(regions,default=region_1,buttons=True,label="Region 1:")):
@interact
def panel_12(country_1s=selector(sorted(dataD[region_1s].keys()),default=defaultCountries[region_1s], label="Land 1:")):
global region_1
region_1=region_1s
global country_1
country_1=country_1s
@interact
def panel_21(region_2s=selector(regions,default=region_2,buttons=True,label="Region 2:")):
@interact
def panel_22(country_2s=selector(sorted(dataD[region_2s].keys()),default=defaultCountries[region_2s], label="Land 2:")):
global region_2
region_2=region_2s
global country_2
country_2=country_2s
@interact
def _(cumulate1=checkbox(False,label='Werte kumulieren'), norm1=checkbox(True,label="Werte normieren")):
global cumulate
cumulate=cumulate1
global norm
norm=norm1
C1=setDates(dataD[region_1][country_1]['cases'])
C2=setDates(dataD[region_2][country_2]['cases'])
D1=setDates(dataD[region_1][country_1]['deaths'])
D2=setDates(dataD[region_2][country_2]['deaths'])
DataCasePlot1=cumulatedNormed(C1,cumulate1,norm1,dataD[region_1][country_1]['population'])
DataCasePlot2=cumulatedNormed(C2,cumulate1,norm1,dataD[region_2][country_2]['population'])
DataDeathPlot1=cumulatedNormed(D1,cumulate1,norm1,dataD[region_1][country_1]['population'])
DataDeathPlot2=cumulatedNormed(D2,cumulate1,norm1,dataD[region_2][country_2]['population'])
labelCase1="COVID-19-Infektionen in "+country_1
labelCase2="COVID-19-Infektionen in "+country_2
labelDeath1="COVID-19-Tote in "+country_1
labelDeath2="COVID-19-Tote in "+country_2
if cumulate:
labelCase1 += " kumuliert";labelCase2 += " kumuliert";
labelDeath1 += " kumuliert";labelDeath2 += " kumuliert";
if norm:
labelCase1 += ", pro 100 000 Einwohner";labelCase2 += ", pro 100 000 Einwohner";
labelDeath1 += ", pro 100 000 Einwohner";labelDeath2 += ", pro 100 000 Einwohner";
show(list_plot(DataCasePlot1, color='blue',legend_label=labelCase1)+list_plot(DataCasePlot2, color='red',legend_label=labelCase2))
show(list_plot(DataDeathPlot1, color='blue',legend_label=labelDeath1)+list_plot(DataDeathPlot2, color='red',legend_label=labelDeath2))
Daten von Woche 2020-01 bis Woche 2021-15 geladen
Interactive function <function panel_11 at 0x7f393370ec10> with 1 widget region_1s: ToggleButtons(descriptio…
Accepted: {"data":{"text/plain":"text/image-filename file","text/image-filename":"tmp_obhhfd0g.png?m=1619374445.6130748"},"source":"sagecell"}
Accepted: {"data":{"text/plain":"text/image-filename file","text/image-filename":"tmp_4_jsa95f.png?m=1619374445.2010787"},"source":"sagecell"}
Accepted: {"data":{"application/sage-clear":{"changed":["cumulate1","norm1"]},"text/plain":"Clear display"},"source":"sagecell"}
Accepted: {"data":{"application/sage-interact":{"new_interact_id":"a2bfddc9-82ec-4dcf-9ff1-5c2bbffad970","controls":{"cumulate1":{"control_type":"checkbox","default":false,"raw":true,"label":"Werte kumulieren","update":true},"norm1":{"control_type":"checkbox","default":true,"raw":true,"label":"Werte normieren","update":true}},"layout":[[["cumulate1",1]],[["norm1",1]],[["_output",1]]],"locations":null,"readonly":false},"text/plain":"Sage Interact"},"source":"sagecell"}
Accepted: {"data":{"application/sage-clear":{"changed":["country_2s"]},"text/plain":"Clear display"},"source":"sagecell"}
Accepted: {"data":{"application/sage-interact":{"new_interact_id":"81d5c376-4291-4d51-9254-007bc8d07895","controls":{"country_2s":{"control_type":"selector","subtype":"list","values":41,"value_labels":["America (total)","Anguilla","Argentina","Aruba","Bahamas","Barbados","Belize","Bermuda","Bolivia","Brazil","British Virgin Islands","Canada","Cayman Islands","Chile","Colombia","Costa Rica","Cuba","Curaçao","Dominica","Dominican Republic","Ecuador","El Salvador","Greenland","Grenada","Guatemala","Guyana","Haiti","Honduras","Jamaica","Mexico","Montserrat","Nicaragua","Panama","Paraguay","Peru","Puerto Rico","Saint Lucia","Sint Maarten","Suriname","Uruguay","Venezuela"],"default":0,"nrows":null,"ncols":null,"raw":true,"width":"None","label":"Land 2:","update":true}},"layout":[[["country_2s",1]],[["_output",1]]],"locations":null,"readonly":false},"text/plain":"Sage Interact"},"source":"sagecell"}
Accepted: {"data":{"application/sage-clear":{"changed":["region_2s"]},"text/plain":"Clear display"},"source":"sagecell"}
Accepted: {"data":{"application/sage-interact":{"new_interact_id":"a8371206-03a6-4fb5-bfec-4b43c4af6b9b","controls":{"region_2s":{"control_type":"selector","subtype":"button","values":5,"value_labels":["Africa","America","Asia","Europe","Oceania"],"default":1,"nrows":1,"ncols":5,"raw":true,"width":"None","label":"Region 2:","update":true}},"layout":[[["region_2s",1]],[["_output",1]]],"locations":null,"readonly":false},"text/plain":"Sage Interact"},"source":"sagecell"}
Accepted: {"data":{"application/sage-clear":{"changed":["country_1s"]},"text/plain":"Clear display"},"source":"sagecell"}
Accepted: {"data":{"application/sage-interact":{"new_interact_id":"8604cebf-66c2-4fa4-ab04-4096a976dc17","controls":{"country_1s":{"control_type":"selector","subtype":"list","values":53,"value_labels":["Albania","Andorra","Armenia","Austria","Azerbaijan","Belarus","Belgium","Bulgaria","Croatia","Cyprus","Czechia","Denmark","EU/EEA (total)","Estonia","Europe (total)","Finland","France","Georgia","Germany","Gibraltar","Greece","Guernsey","Hungary","Iceland","Ireland","Italy","Jersey","Kosovo","Latvia","Liechtenstein","Lithuania","Luxembourg","Malta","Moldova","Monaco","Montenegro","Netherlands","North Macedonia","Norway","Poland","Portugal","Romania","Russia","San Marino","Serbia","Slovakia","Slovenia","Spain","Sweden","Switzerland","Turkey","Ukraine","United Kingdom"],"default":18,"nrows":null,"ncols":null,"raw":true,"width":"None","label":"Land 1:","update":true}},"layout":[[["country_1s",1]],[["_output",1]]],"locations":null,"readonly":false},"text/plain":"Sage Interact"},"source":"sagecell"}
Accepted: {"data":{"application/sage-clear":{"changed":["region_1s"]},"text/plain":"Clear display"},"source":"sagecell"}
Accepted: {"data":{"application/sage-interact":{"new_interact_id":"a0768b44-015c-43a4-9b61-cdf3715b1a65","controls":{"region_1s":{"control_type":"selector","subtype":"button","values":5,"value_labels":["Africa","America","Asia","Europe","Oceania"],"default":3,"nrows":1,"ncols":5,"raw":true,"width":"None","label":"Region 1:","update":true}},"layout":[[["region_1s",1]],[["_output",1]]],"locations":null,"readonly":false},"text/plain":"Sage Interact"},"source":"sagecell"}
Accepted: {"data":{"text/plain":"html","text/html":"Daten von Woche 2020-01 bis Woche 2021-15 geladen"},"source":"sagecell"}
Accepted: {"data":{"text/plain":"html","text/html":"\n<style type=\"text/css\">\n.sagecell_interactContainer{border: none; margin: 0px; padding: 0px}\n.sagecell_interactControlLabel{min-width: 8ex; text-align: left !important}\n.sagecell_interactOutput{padding: 0px}\n</style>\n"},"source":"sagecell"}
Messages
Messages