Example #1
0
import pandas as pd
import matplotlib.pyplot as plt
from util import country_vs_date
import numpy as np

confirmed = pd.read_csv(
    "data/COVID-19/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv"
)
confirmed = country_vs_date(confirmed)
fig, ax = plt.subplots()
# Remove Total column, transpose it to make countries as index and we get the last column which is the latest date
confirmed_per_country = confirmed.drop(columns=["Total"]).T.iloc[:, -1]
xticks = np.arange(0, 600001, 50000)
confirmed_per_country.hist(bins=xticks, ax=ax)
# Set up xticks and yticks interval
ax.set_xticks(xticks, minor=True)
ax.set_yticks(np.arange(0, 181, 5), minor=True)
# Set up grid alpha level
ax.grid(which="minor", alpha=0.2)
ax.grid(which="major", alpha=0.5)
plt.title("Number of confirmed cases till 12/4/2020")
plt.xlabel("Number of confirmed cases")
plt.ylabel("Number of countries")
plt.show()
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from util import country_vs_date

confirmed = pd.read_csv(
    "data/COVID-19/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv"
)
total_confirmed = country_vs_date(confirmed).Total

deaths = pd.read_csv(
    "data/COVID-19/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv"
)
total_deaths = country_vs_date(deaths).Total

recovered = pd.read_csv(
    "data/COVID-19/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_recovered_global.csv"
)
total_recovered = country_vs_date(recovered).Total

fig, ax = plt.subplots(figsize=(8, 8))
total_confirmed.plot(ax=ax, label="Confirmed")
plt.fill_between(total_confirmed.index, total_confirmed.values)
total_recovered.plot(ax=ax, label="Recovered")
plt.fill_between(total_confirmed.index, total_recovered.values)
total_deaths.plot(ax=ax, label="Deaths")
plt.fill_between(total_confirmed.index, total_deaths.values)
freq = 3
# setting xticks = the dates with the frequency of 3, and setting them vertical, any df.index works since they are the same
plt.xticks(np.arange(0, len(total_confirmed.index), step=freq),
           total_confirmed.index[::freq],
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from util import country_vs_date
from sklearn.linear_model import LinearRegression
import matplotlib.ticker as mtick
import seaborn as sns

confirmed = country_vs_date(
    pd.read_csv(
        "data/COVID-19/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv"
    ))

deaths = country_vs_date(
    pd.read_csv(
        "data/COVID-19/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv"
    ))

recovered = country_vs_date(
    pd.read_csv(
        "data/COVID-19/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_recovered_global.csv"
    ))

# Computing death rate and recovery rate
death_rate = (deaths * 100).div(confirmed).fillna(0)
death_rate = death_rate.T.reset_index().rename(columns={
    "Country/Region": "Country",
    "4/12/20": "Death rate"
})
death_rate = death_rate.iloc[:, [0, -1]]