# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     name: python3
# ---

# + [markdown] id="fRUlRO7vejik"
# > Notebook used to split the raw data until June 30, 2020 and after this date. The first dataset will be used in the study to train the models and the other one can be used to test the models.
#
# ---

# + [markdown] id="Audb9d0XzD_l"
# # **Libraries**

# + [markdown] id="XYbCAEO8iHgj"
# Import of some libraries that will be used.

# + id="U4ZOsqYcxnIc" executionInfo={"status": "ok", "timestamp": 1623846226609, "user_tz": 180, "elapsed": 10, "user": {"displayName": "<NAME>", "photoUrl": "", "userId": "13718893696373545505"}}
import numpy as np
import pandas as pd 
import matplotlib.pyplot as plt

# + [markdown] id="2Kr8YaaFzHsM"
# # **Data**

# + [markdown] id="RIzAFxuZiNp-"
# COVID-19 data in Brazil provided by
#
# - [Wesley Cota GitHub](https://github.com/wcota/covid19br)

# + id="r3L0Q3rzgm9m" colab={"base_uri": "https://localhost:8080/", "height": 309} executionInfo={"status": "ok", "timestamp": 1623846250445, "user_tz": 180, "elapsed": 885, "user": {"displayName": "<NAME>", "photoUrl": "", "userId": "13718893696373545505"}} outputId="938a4120-7bab-44e6-8d94-a87abd50d5e6"
# Reading data - wcota
data_path = 'https://raw.githubusercontent.com/wcota/covid19br/master/cases-brazil-states.csv'

df = pd.read_csv(data_path) 
df.head()

# + colab={"base_uri": "https://localhost:8080/"} id="ZEJKiqGozeN1" executionInfo={"status": "ok", "timestamp": 1623846679842, "user_tz": 180, "elapsed": 363, "user": {"displayName": "<NAME>", "photoUrl": "", "userId": "13718893696373545505"}} outputId="860a38c3-0c49-40d1-8b42-9de9ad21613e"
df.shape

# + [markdown] id="hj1BqMdh8J7p"
# ## **Data until June 30**

# + [markdown] id="zVZeDOCQikLN"
# First dataset until June 30.

# + colab={"base_uri": "https://localhost:8080/", "height": 326} id="1nAyWpmlyKfu" executionInfo={"status": "ok", "timestamp": 1623846913102, "user_tz": 180, "elapsed": 509, "user": {"displayName": "<NAME>", "photoUrl": "", "userId": "13718893696373545505"}} outputId="d623c0d3-1929-478a-b577-d81ae1fa9dcc"
date = '2020-06-30'

df_june = df[df['date'] <= date].copy()
print(df_june.shape)
df_june.tail()

# + colab={"base_uri": "https://localhost:8080/", "height": 326} id="3v0kiMuq0oB5" executionInfo={"status": "ok", "timestamp": 1623847211337, "user_tz": 180, "elapsed": 469, "user": {"displayName": "<NAME>", "photoUrl": "", "userId": "13718893696373545505"}} outputId="99ce9917-2287-4f03-908d-4d627806aa5b"
# Dataset from RJ state
state = 'RJ'

df_state = df_june[df_june.state == state].reset_index()
print(df_state.shape)
df_state.head()

# + id="7w9T4EoA1QDJ" executionInfo={"status": "ok", "timestamp": 1623847250343, "user_tz": 180, "elapsed": 378, "user": {"displayName": "<NAME>", "photoUrl": "", "userId": "13718893696373545505"}}
# Creating new recovered column
df_state["newRecovered"] = df_state["recovered"].diff()
df_state.newRecovered.fillna(0, inplace=True)
df_state.recovered.fillna(0, inplace=True)

# + id="TibBQhz01QDK" executionInfo={"status": "ok", "timestamp": 1623847252538, "user_tz": 180, "elapsed": 527, "user": {"displayName": "<NAME>", "photoUrl": "", "userId": "13718893696373545505"}}
# Creating active cases column (Infected)
active_infected = [df_state["totalCases"].iloc[0]]
for nc, nr in zip(df_state["newCases"].iloc[1:], 
                  df_state["newRecovered"].iloc[1:]):
    active_infected.append(active_infected[-1] + nc - nr)
df_state["activeCases"] = active_infected

# + colab={"base_uri": "https://localhost:8080/", "height": 501} id="m6EcOBe91zhN" executionInfo={"status": "ok", "timestamp": 1623848460204, "user_tz": 180, "elapsed": 574, "user": {"displayName": "<NAME>", "photoUrl": "", "userId": "13718893696373545505"}} outputId="662fa4b7-e448-485e-8474-a0183e196b0c"
# Ploting Active Cases and Recovered curves from RJ state
plot1 = 'activeCases'
plot2 = 'recovered'

fig, ax = plt.subplots(figsize=(20, 8))
ax1 = ax.plot(df_state.date, df_state[plot1], label='Active cases', linewidth=3)
ax2 = ax.plot(df_state.date, df_state[plot2], label='Recovered', linewidth=3)
ax.set_xlabel('Date', size=14)
ax.set_ylabel('Cases', size=14)

ax.legend()
show_index = [0,20,40,60,80,100,117]
ax.set_xticks(df_state.loc[show_index, 'date'])
ax.set_xticklabels(df_state.loc[show_index, 'date'])
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)

plt.show()

# + [markdown] id="iUHoLFPO76s-"
# ## **After June 30**

# + [markdown] id="XClHVt8PirnN"
# Dataset with the data after June 30.

# + colab={"base_uri": "https://localhost:8080/", "height": 326} id="KJ4AO_HCyzmJ" executionInfo={"status": "ok", "timestamp": 1623846905014, "user_tz": 180, "elapsed": 388, "user": {"displayName": "<NAME>", "photoUrl": "", "userId": "13718893696373545505"}} outputId="534b7edc-17ee-4f7e-cf24-1f838a9cde05"
df_after_june = df[df['date'] > date].copy()
print(df_after_june.shape)
df_after_june.head()

# + colab={"base_uri": "https://localhost:8080/", "height": 326} id="ezTCuvvi6aL2" executionInfo={"status": "ok", "timestamp": 1623848548299, "user_tz": 180, "elapsed": 383, "user": {"displayName": "<NAME>", "photoUrl": "", "userId": "13718893696373545505"}} outputId="786defca-dd16-47ea-fda9-2daeef322d57"
# Dataset from SP state
state = 'SP'

df_state = df_after_june[df_after_june.state == state].reset_index()
print(df_state.shape)
df_state.head()

# + id="cW7VBo5t6aML" executionInfo={"status": "ok", "timestamp": 1623848560424, "user_tz": 180, "elapsed": 492, "user": {"displayName": "<NAME>", "photoUrl": "", "userId": "13718893696373545505"}}
# Creating new recovered column
df_state["newRecovered"] = df_state["recovered"].diff()
df_state.newRecovered.fillna(0, inplace=True)
df_state.recovered.fillna(0, inplace=True)

# + id="FN2vvgMA6aMM" executionInfo={"status": "ok", "timestamp": 1623848562906, "user_tz": 180, "elapsed": 371, "user": {"displayName": "<NAME>", "photoUrl": "", "userId": "13718893696373545505"}}
# Creating active cases column (Infected)
active_infected = [df_state["totalCases"].iloc[0]]
for nc, nr in zip(df_state["newCases"].iloc[1:], 
                  df_state["newRecovered"].iloc[1:]):
    active_infected.append(active_infected[-1] + nc - nr)
df_state["activeCases"] = active_infected

# + colab={"base_uri": "https://localhost:8080/", "height": 512} id="9mJ4Kfu56aMN" executionInfo={"status": "ok", "timestamp": 1623848865361, "user_tz": 180, "elapsed": 829, "user": {"displayName": "<NAME>", "photoUrl": "", "userId": "13718893696373545505"}} outputId="5538a009-8dfd-4d14-b6f3-5bd25ceb2f80"
# Ploting Active Cases and Recovered curves from SP state
plot1 = 'activeCases'
plot2 = 'recovered'

fig, ax = plt.subplots(figsize=(20, 8))
ax1 = ax.plot(df_state.date, df_state[plot1], label='Active cases', linewidth=3)
ax2 = ax.plot(df_state.date, df_state[plot2], label='Recovered', linewidth=3)
ax.set_xlabel('Date', size=14)
ax.set_ylabel('Cases', size=14)

ax.legend()
show_index = np.round(np.linspace(0, 349, 11))
ax.set_xticks(df_state.loc[show_index, 'date'])
ax.set_xticklabels(df_state.loc[show_index, 'date'])
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)

plt.show()

StarcoderdataJupyterScriptsDedupFiltered