COVID-19 Ländervergleich
Ingo Dahn (dahn@dahn-research.eu)
Mit diesem Notebook kann man die Entwicklung der wöchentlichen COVID-19-Daten seit Anfang 2020 (Infizierte und Verstorbene) bis zum 14.12.2020 in zwei Ländern vergleichen. Diese Seite wird unter der Creative Commons Lizenz CC BY-NC-SA 4.0 veröffentlicht.
Die Daten stammen von https://opendata.ecdc.europa.eu/covid19/casedistribution/csv. Aktuellere Daten werden hier nicht bereitgestellt.
import pandas as pd
url="https://dahn-research.eu/corona/casedistribution.csv"
data=pd.read_csv(url)
data=data.sort_values(by=['countriesAndTerritories','year','month','day'])
dataV=data.values
dataT=data.T
dataTV=dataT.values
regions=sorted(set(dataTV[10]))
dataD={}
for n in range(0,len(dataV)):
line=dataV[n]
region=line[10];country=line[6];date=line[0]; cases=line[4]; deaths=line[5]; population=line[9]
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, 'dates':[], 'cases':[],'deaths':[]}
dataD[region][country]['dates'].append(date)
dataD[region][country]['cases'].append(cases)
dataD[region][country]['deaths'].append(deaths)
defaultCountries={'Europe': 'Germany', 'America': 'United_States_of_America','Asia': 'China', 'Africa':'South_Africa', 'Oceania': 'Australia'}
datesAll=dataD['Europe']['Germany']['dates']
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 %s bis %s geladen"%(datesAll[0],datesAll[dataNr-1])))
datesMap={}
for n in range(0,dataNr):
datesMap[datesAll[n]]=n
regions=sorted(defaultCountries.keys())
def meanedList(L,n):
LL=[sum(L[i-n:i])/n for i in range(n,len(L)+1)]
return LL
def setDates(Dates,Data):
LL=[0 for n in range(0,dataNr)]
for i in range(0,len(Dates)):
LL[datesMap[Dates[i]]]=Data[i]
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,m,c,n,P):
if m:
casePlotData0=meanedList(L,7)
else:
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='United_States_of_America'
@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 _(mean1=checkbox(True,label='Wochenmittel'), cumulate1=checkbox(False,label='Werte kumulieren'), norm1=checkbox(True,label="Werte normieren")):
global meaned
meaned=mean1
global cumulate
cumulate=cumulate1
global norm
norm=norm1
C1=setDates(dataD[region_1][country_1]['dates'],dataD[region_1][country_1]['cases'])
C2=setDates(dataD[region_2][country_2]['dates'],dataD[region_2][country_2]['cases'])
D1=setDates(dataD[region_1][country_1]['dates'],dataD[region_1][country_1]['deaths'])
D2=setDates(dataD[region_2][country_2]['dates'],dataD[region_2][country_2]['deaths'])
DataCasePlot1=cumulatedNormed(C1,mean1,cumulate1,norm1,dataD[region_1][country_1]['population'])
DataCasePlot2=cumulatedNormed(C2,mean1,cumulate1,norm1,dataD[region_2][country_2]['population'])
DataDeathPlot1=cumulatedNormed(D1,mean1,cumulate1,norm1,dataD[region_1][country_1]['population'])
DataDeathPlot2=cumulatedNormed(D2,mean1,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";
if meaned:
labelCase1 += ", gemittelt";labelCase2 += ", gemittelt";
#labelDeath1 += ", gemittelt";labelDeath2 += ", gemittelt";
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 31/12/2019 bis 14/12/2020 geladen
Interactive function <function panel_11 at 0x7f0c3a3585e0> with 1 widget region_1s: ToggleButtons(descriptio…
Accepted: {"data":{"text/plain":"text/image-filename file","text/image-filename":"tmp_0c2j5b2y.png?m=1614077581.0460393"},"source":"sagecell"}
Accepted: {"data":{"text/plain":"text/image-filename file","text/image-filename":"tmp_ur2xocub.png?m=1614077580.3259945"},"source":"sagecell"}
Accepted: {"data":{"application/sage-clear":{"changed":["mean1","cumulate1","norm1"]},"text/plain":"Clear display"},"source":"sagecell"}
Accepted: {"data":{"application/sage-interact":{"new_interact_id":"13c312c1-d500-4674-b96e-49d2d5a30667","controls":{"mean1":{"control_type":"checkbox","default":true,"raw":true,"label":"Wochenmittel","update":true},"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":[[["mean1",1]],[["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":"46ff95a0-9726-4698-a7b3-32aa60c8a6a8","controls":{"country_2s":{"control_type":"selector","subtype":"list","values":49,"value_labels":["Anguilla","Antigua_and_Barbuda","Argentina","Aruba","Bahamas","Barbados","Belize","Bermuda","Bolivia","Bonaire, Saint Eustatius and Saba","Brazil","British_Virgin_Islands","Canada","Cayman_Islands","Chile","Colombia","Costa_Rica","Cuba","Curaçao","Dominica","Dominican_Republic","Ecuador","El_Salvador","Falkland_Islands_(Malvinas)","Greenland","Grenada","Guatemala","Guyana","Haiti","Honduras","Jamaica","Mexico","Montserrat","Nicaragua","Panama","Paraguay","Peru","Puerto_Rico","Saint_Kitts_and_Nevis","Saint_Lucia","Saint_Vincent_and_the_Grenadines","Sint_Maarten","Suriname","Trinidad_and_Tobago","Turks_and_Caicos_islands","United_States_Virgin_Islands","United_States_of_America","Uruguay","Venezuela"],"default":46,"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":"72483291-f80c-4423-ba38-d688982461b3","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":"038bde23-e7d8-465c-b7c8-0538a873fb24","controls":{"country_1s":{"control_type":"selector","subtype":"list","values":55,"value_labels":["Albania","Andorra","Armenia","Austria","Azerbaijan","Belarus","Belgium","Bosnia_and_Herzegovina","Bulgaria","Croatia","Cyprus","Czechia","Denmark","Estonia","Faroe_Islands","Finland","France","Georgia","Germany","Gibraltar","Greece","Guernsey","Holy_See","Hungary","Iceland","Ireland","Isle_of_Man","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":"3c50c305-7deb-4689-8de6-133bc4e0aa38","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 31/12/2019 bis 14/12/2020 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