# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernel_info:
#     name: python3-azureml
#   kernelspec:
#     display_name: Python 3.6 - AzureML
#     language: python
#     name: python3-azureml
# ---

# +
import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

# !curl https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv  -o ../covid-19-confirmed-cases.csv
# !curl https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_recovered_global.csv  -o ../covid-19-recovered-cases.csv
# !curl https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv  -o ../covid-19-recovered-deaths.csv
# -

ConfirmedCases = pd.read_csv('../covid-19-confirmed-cases.csv')
RecoveredCases = pd.read_csv('../covid-19-recovered-cases.csv')
Deaths = pd.read_csv('../covid-19-recovered-deaths.csv')

# + jupyter={"outputs_hidden": false, "source_hidden": false} nteract={"transient": {"deleting": false}}
ConfirmedCases = Dataset.get_by_name(workspace, name='COVID19_Confirmed').to_pandas_dataframe()
RecoveredCases = Dataset.get_by_name(workspace, name='COVID19_Recovered').to_pandas_dataframe()
Deaths = Dataset.get_by_name(workspace, name='COVID19_Deaths').to_pandas_dataframe()
print("Succeeded")

# + jupyter={"outputs_hidden": false, "source_hidden": false} nteract={"transient": {"deleting": false}}
ConfirmedCases_ValueColumns = ConfirmedCases.columns[4:]
RecoveredCases_ValueColumns = RecoveredCases.columns[4:]
Deaths_ValueColumns = Deaths.columns[4:]
print("Succeeded")

# + jupyter={"outputs_hidden": false, "source_hidden": false} nteract={"transient": {"deleting": false}}
ConfirmedCases = pd.melt(ConfirmedCases, id_vars=['Country/Region'], 
                          value_vars = ConfirmedCases_ValueColumns,
                          var_name = "Date",
                         value_name = "ConfirmedCases")

RecoveredCases = pd.melt(RecoveredCases, id_vars=['Country/Region'], 
                          value_vars = RecoveredCases_ValueColumns,
                          var_name = "Date",
                         value_name = "RecoveredCases")

Deaths = pd.melt(Deaths, id_vars = ["Country/Region"],
                 value_vars = Deaths_ValueColumns,
                 var_name = "Date",
                 value_name = "Deaths")
print("Succeeded")

# + jupyter={"outputs_hidden": false, "source_hidden": false} nteract={"transient": {"deleting": false}}
ConfirmedCases["Date"] = pd.to_datetime(ConfirmedCases["Date"])

RecoveredCases["Date"] = pd.to_datetime(RecoveredCases["Date"])

Deaths["Date"] = pd.to_datetime(Deaths["Date"])

# + jupyter={"outputs_hidden": false, "source_hidden": false} nteract={"transient": {"deleting": false}}
ConfirmedCases_ByDate = pd.pivot_table(ConfirmedCases, values='ConfirmedCases', 
                                       index=["Date"],
                                       aggfunc=np.sum).sort_values(by = "Date")


RecoveredCases_ByDate = pd.pivot_table(RecoveredCases,
                                      values = "RecoveredCases",
                                      index = ["Date"],
                                      aggfunc = np.sum).sort_values(by = "Date")

Deaths_ByDate = pd.pivot_table(Deaths,
                              values = "Deaths",
                              index = ["Date"],
                              aggfunc = np.sum).sort_values(by = "Date")


# + jupyter={"outputs_hidden": false, "source_hidden": false} nteract={"transient": {"deleting": false}}
#Creating By Country Pivot Tables
ConfirmedCases_ByCountry = pd.pivot_table(ConfirmedCases,
                                         values = "ConfirmedCases",
                                         index = ["Country/Region"],
                                         aggfunc = np.max)

RecoveredCases_ByCountry = pd.pivot_table(RecoveredCases,
                                         values = "RecoveredCases",
                                         index = ["Country/Region"],
                                         aggfunc = np.max)

Deaths_ByCountry = pd.pivot_table(Deaths,
                                 values = "Deaths",
                                 index = ["Country/Region"],
                                 aggfunc = np.max)
print("Succeeded")

# + jupyter={"outputs_hidden": false, "source_hidden": false} nteract={"transient": {"deleting": false}}
COVID19_ByDate = ConfirmedCases_ByDate.merge(RecoveredCases_ByDate, on = "Date").merge(Deaths_ByDate, on = "Date")
COVID19_ByCountry = ConfirmedCases_ByCountry.merge(RecoveredCases_ByCountry, on = "Country/Region").merge(Deaths_ByCountry, on = "Country/Region")
print("Succeeded")

# + jupyter={"outputs_hidden": false, "source_hidden": false} nteract={"transient": {"deleting": false}}


StarcoderdataJupyterScriptsDedupFiltered