<jupyter_start><jupyter_text>Visualisation des données<jupyter_code>import os

import pandas as pd
# Répertoire du fichier de données
PROCESSED_DIR = '/Users/EnzoButhiot/Documents/AMSE/MAG3/S2/Projet_mignot/corona/data/processed/'

# Table principale
ALL_DATA_FILE = 'all_data.csv'
epidemie_df = (pd.read_csv(os.path.join(PROCESSED_DIR, ALL_DATA_FILE), parse_dates=['Last Update'])
               .assign(day=lambda _df: _df['Last Update'].dt.date))
epidemie_df.head()
epidemie_df.dtypes
epidemie_df['Country/Region'].value_counts()<jupyter_output><empty_output><jupyter_text>Epidémie en France<jupyter_code>! pip install seaborn
import seaborn as sns

sns.set()
import matplotlib.pyplot as plt
%matplotlib inline

epidemie_df[(epidemie_df['Country/Region'] == 'France') & (epidemie_df['Province/State'] == 'France')] \
.sort_values('day', ascending=False).head()




france_df.head(), france_df.tail()

epidemie_df[epidemie_df['Country/Region'] == 'France'].set_index('day')['Confirmed'].plot(figsize=(10, 5));
epidemie_df[epidemie_df['Country/Region'] == 'Italy'].set_index('day')['Confirmed'].plot(figsize=(15, 5));
epidemie_df[epidemie_df['Country/Region'] == 'Mainland China'].set_index('day')['Confirmed'].plot(figsize=(15, 5));
(epidemie_df[epidemie_df['Country/Region'] == 'Mainland China']
 .groupby('day')
 .agg({'Confirmed': 'sum'})
).plot(figsize=(12, 5));
(epidemie_df[epidemie_df['Country/Region'] == 'Mainland China']
 .fillna(value=0)
 .groupby('day')
 .agg({'Confirmed': 'sum', 'Deaths': 'sum'})
).plot(figsize=(12, 5));
epidemie_df[epidemie_df['Country/Region'] == 'France'].set_index('day')[ ['Confirmed', 'Deaths'] ].plot(figsize=(10, 5));
(epidemie_df[epidemie_df['Country/Region'] == 'France']
 .set_index('day')[ ['Confirmed', 'Deaths'] ]
 .plot(secondary_y=['Deaths'], figsize=(10, 5))
);
(epidemie_df[epidemie_df['Country/Region'] == 'France']
 .set_index('day')[ ['Confirmed', 'Recovered'] ]
 .plot(secondary_y=['Recovered'], figsize=(10, 5))
);
china_df = (epidemie_df[epidemie_df['Country/Region'] == 'Mainland China']
            .groupby('day')
            .agg({'Confirmed': 'sum', 'Deaths': 'sum', 'Recovered': 'sum'})
           )
china_df.head()
china_df.plot(secondary_y=['Deaths'], figsize=(12, 5));
(china_df
 .assign(death_rate=lambda _df: _df['Deaths'] / _df['Confirmed'])
 [['Confirmed', 'death_rate']]
 .plot(secondary_y=['death_rate'], figsize=(12, 5))
);
plt.figure(figsize=(12, 5))
sns.lineplot(data=epidemie_df[epidemie_df['Country/Region'] == 'France'].set_index('day')['Confirmed']);
epidemie_df.groupby(['Country/Region', 'day']).agg({'Confirmed': 'sum', 'Deaths': 'sum', 'Recovered': 'sum'})
EUROPE = ['France', 'Germany', 'UK', 'Spain']
import matplotlib.pyplot as plt

g = sns.FacetGrid(epidemie_df[epidemie_df['Country/Region'].isin(EUROPE)],
                  col="Country/Region", col_wrap=2, height=2.5, aspect=2.5)
g = g.map(plt.plot, "day", "Confirmed");
import plotly.offline as py
import plotly.graph_objs as go
france_df = epidemie_df[epidemie_df['Country/Region'] == 'France']
data = [go.Scatter(x=france_df['day'],
                   y=france_df['Confirmed'],
                   name='Cas confirmés en France'
                  )]
py.iplot(data)
data = [go.Scatter(x=france_df['day'],
                   y=france_df['Confirmed'],
                   name='Confirmés/France'
                  ),
        go.Scatter(x=epidemie_df[epidemie_df['Country/Region'] == 'Germany']['day'],
                   y=epidemie_df[epidemie_df['Country/Region'] == 'Germany']['Confirmed'],
                   name='Confirmés/Allemagne'
                  )
       ]

layout = dict(
    title = "Epidémie Corona Virus",
    xaxis = dict(range = ['2020-01-22', '2020-03-05'])
)

fig = dict(data=data, layout=layout)
py.iplot(fig)
import yaml

ENV_FILE = "/Users/EnzoButhiot/Documents/corona/env.yaml"
with open(ENV_FILE) as f: 
    params=yaml.load(f, Loader=yaml.FullLoader)
params
os.path.abspath(ENV_FILE)
os.path.dirname(os.path.abspath(ENV_FILE))
import datetime

epidemie_df[epidemie_df['Country/Region'] == 'Mainland China'][lambda df: df.day <= datetime.date(2020, 3, 26)] \
.sort_values('day').tail(20)
epidemie_df['day'].min()
epidemie_df['day'].max()
epidemie_df['day'].unique()
str(epidemie_df['day'].min())
(epidemie_df['day'].max() - epidemie_df['day'].min()).days
{i:str(date) for i, date in enumerate(epidemie_df['day'].unique())}
epidemie_df.apply(lambda r: r['Country/Region'] + ' (' + str(r['Confirmed']) + ')', axis=1)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.20146438872864433, 'fraction_numerical': 0.014865764366540937, 'mean_word_length': 5.261111111111111, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '132818', 'license': 'MIT', 'n_tokens_mistral': 1837, 'n_tokens_neox': 1696, 'n_words': 244, 'path': 'notebooks/visualisation_epidemie.ipynb', 'repo_name': 'enzo-buthiot/corona', 'size': '4507'}