<jupyter_start><jupyter_text>Basic stats on the evolution of COVID-19 hospitalizations in departments<jupyter_code>%load_ext lab_black
%matplotlib inline
import matplotlib.pyplot as plt
from datetime import timedelta, date
import pandas as pd
import warnings

warnings.filterwarnings("ignore")
pd.plotting.register_matplotlib_converters()
covid_url = (
    "https://www.data.gouv.fr/fr/datasets/r/63352e38-d353-4b54-bfd1-f1b3ee1cabd7"
)
filter_dep = ["971", "972", "973", "974", "976"]  # only metropolitan France
figsize = (15, 10)<jupyter_output><empty_output><jupyter_text>Load table with COVID-19 data (figures by dates)<jupyter_code>df = pd.read_csv(covid_url, sep=";", parse_dates=True, index_col=2)
df = df.query("sexe == 0")  # sum male/female
df.drop(columns=["sexe"], inplace=True)
df.query("dep not in @filter_dep", inplace=True)
df.sort_index(inplace=True)
df.head(2)
last_day = df.index.max()
previous_day = last_day - timedelta(days=1)
print("Evolution from ", previous_day, " to ", last_day)<jupyter_output>Evolution from  2020-04-21 00:00:00  to  2020-04-22 00:00:00<jupyter_text>Build a new dataframe with data from two latest days and the associated evolution<jupyter_code>sdf = df.loc[last_day]
sdf.reset_index(inplace=True)
pdf = df.loc[previous_day]
pdf.reset_index(inplace=True)
frame = {"dep": sdf["dep"], "prev_hosp": pdf["hosp"], "last_hosp": sdf["hosp"]}
stats = pd.DataFrame(frame)
stats["diff"] = stats["last_hosp"] - stats["prev_hosp"]
stats["percent"] = stats["diff"] / stats["prev_hosp"] * 100
stats.head()<jupyter_output><empty_output><jupyter_text>Departments with highest number of hospitalizations on the latest day<jupyter_code>stats.sort_values(by="last_hosp", ascending=False).head()<jupyter_output><empty_output><jupyter_text>Min, max, mean of evolution between the two latest days (in sum and %)<jupyter_code>print(
    "Min: ",
    stats["diff"].min(),
    " Mean: ",
    stats["diff"].mean(),
    " Max: ",
    stats["diff"].max(),
)
print(
    "Min %: ",
    stats.percent.min(),
    " Mean %: ",
    stats.percent.mean(),
    " Max %: ",
    stats.percent.max(),
)<jupyter_output>Min %:  -24.390243902439025  Mean %:  -1.5271884997288405  Max %:  57.14285714285714<jupyter_text>List of departments with a drecrease of hospitalizations (last two days)<jupyter_code>stats.query("diff < 0")
print(stats.query("diff < 0").shape)<jupyter_output>(58, 5)<jupyter_text>Departments with highest evolution of hospitalizations (total number)<jupyter_code>stats.sort_values(by="diff", ascending=False).head()<jupyter_output><empty_output><jupyter_text>Departments with highest rate of hospitalizations (%)<jupyter_code>stats.sort_values(by="percent", ascending=False).head()<jupyter_output><empty_output><jupyter_text>Focus on some departments<jupyter_code>stats.query("dep=='75'")
stats.query("dep=='71'")
stats.query("dep=='31'")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1555478741790529, 'fraction_numerical': 0.0473556861389561, 'mean_word_length': 6.821621621621621, 'pattern_counts': {'":': 3, '<': 36, '<?xml version=': 0, '>': 34, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '660362', 'license': 'MIT', 'n_tokens_mistral': 1158, 'n_tokens_neox': 1060, 'n_words': 196, 'path': 'demo-stats.ipynb', 'repo_name': 'lvwuwei/covid-france', 'size': '2893'}