The Second version is on my Gitlab account here
Sample Charts
The first Version :
Code:
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
#Population data from : https://www.insee.fr/fr/statistiques/1893198
popEx = pd.read_csv("population_2020.csv",sep=";")
popEx
#datetime convert based on https://gist.github.com/gjreda/7433f5f70299610d9b6b
from datetime import datetime
#convert from 2020-03-19
to_datetime = lambda d: datetime.strptime(d, '%Y-%m-%d')
#convert from 19/03/2020
to_frDate = lambda dt: datetime.strptime(dt,'%d/%m/%Y')
#données des test PCR issue de santé public
#PCR data from : https://www.data.gouv.fr/fr/datasets/donnees-relatives-aux-resultats-des-tests-virologiques-covid-19/
raw_tests = pd.read_csv("sp-pos-quot-dep-2020-11-26-19h15.csv",sep=";",dtype={"dep":str,"P":int,"T":int}, converters={'jour': to_datetime})
raw_tests["Cas Positifs"] = np.nan
raw_tests["positivity"]= (100*raw_tests["P"])/raw_tests["T"]
#hospitalisation data from : https://www.data.gouv.fr/fr/datasets/donnees-hospitalieres-relatives-a-lepidemie-de-covid-19/
raw_new_hosp=pd.read_csv("donnees-hospitalieres-nouveaux-covid19-2020-11-26-19h03.csv",sep=";",dtype={"dep":str,"incid_hosp":int,"incid_rea":int,"incid_dc":int,"incid_rad":int},converters={"jour":to_datetime})
raw_new_hosp["hosp"] =np.nan # new column used for smoothing the data
#selected departement
deps=["06","13","38","42","69","75","83"]
for d in deps :
#departement data: population and Name
detail_dep = popEx.loc[popEx["dep"]==d, ["Nom_dep","population"]]
nom_dep=detail_dep.iloc[0,0]
pop_dep = detail_dep.iloc[0,1]
print(" Le nom du département est :" + nom_dep +" , et la population en 2020 est estimée à :" + pop_dep)
#PCR Test DATA per Departement
raw_tests_dep = raw_tests.loc[ (raw_tests["cl_age90"]==0) & (raw_tests["dep"]==d),["jour","P","T","Cas Positifs","positivity"] ]
#check that filtered data is not empty
if not raw_tests_dep.empty:
#Smoothing over one week in order to remove weekend distortions
raw_tests_dep["Cas Positifs"] = raw_tests_dep["P"].rolling(7).mean()
plt.rcParams["figure.figsize"] = [16,9]
raw_tests_dep.plot(x="jour",y=["Cas Positifs"], title= "Covid dans " + d +"("+nom_dep +")",grid=True)
plt.show()
plt.rcParams["figure.figsize"] = [8,6]
raw_tests_dep.tail(45).plot(x="jour",y=["Cas Positifs"], title= "Covid dans " + d +"("+nom_dep +")",grid=True)
plt.show()
print( d )
print( raw_tests_dep.tail(10))
else:
print( "PCR Tests data for :" +d + " is EMPTY")
#Hospitalisation Data
raw_hosp_dep= raw_new_hosp.loc[raw_new_hosp["dep"]==d,["jour","hosp","incid_hosp","incid_rea"]]
if not raw_hosp_dep.empty :
#Smoothing over one week in order to remove weekend distortions
raw_hosp_dep["hosp"]= raw_hosp_dep["incid_hosp"].rolling(7).mean()
plt.rcParams["figure.figsize"] = [16,9]
raw_hosp_dep.plot(x="jour",y=["hosp"], title= "Admissions à l'hopital pour le COVID dans " + d +"("+nom_dep +")",grid=True)
plt.show()
plt.rcParams["figure.figsize"] = [8,6]
raw_hosp_dep.tail(45).plot(x="jour",y=["hosp"], title= "Admissions à l'hopital pour le COVID dans " + d +"("+nom_dep +")",grid=True)
plt.show()
print( "Hospitalisation dans " + d )
print( raw_hosp_dep.tail(10))
else:
print( " The Hospital admissions data for department:" +d + " is EMPTY")