<jupyter_start><jupyter_text>Interactive SessionPresented by: <NAME>NISER Coding Club17 Jan 2021<jupyter_code>import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
confirmed_data = pd.read_csv("data/confirmed.csv")<jupyter_output><empty_output><jupyter_text>Seeing your data- head- tail- columns<jupyter_code>confirmed_data
confirmed_data.head(12)
confirmed_data.tail(15)
confirmed_data.columns<jupyter_output><empty_output><jupyter_text>Filtering and Removing stuff<jupyter_code>confirmed_data = confirmed_data.drop(["Lat", "Long", "Province/State"], axis=1)
confirmed_data
confirmed_data["Country/Region"] == "Algeria"
confirmed_data[confirmed_data["Country/Region"] == "Algeria"]
confirmed_data[confirmed_data["Country/Region"] == "Australia"]
countries = confirmed_data["Country/Region"].unique()<jupyter_output><empty_output><jupyter_text>Random<jupyter_code>confirmed_data[confirmed_data["Country/Region"] == "Australia"].sum(axis=0)
confirmed_data[confirmed_data.duplicated(["Country/Region"])]
duplicated_countires = confirmed_data[confirmed_data.duplicated(["Country/Region"])]["Country/Region"].unique()
for duplicate_country in duplicated_countires:    
    current_country_data = confirmed_data[confirmed_data["Country/Region"] == duplicate_country].sum(axis=0)
    current_country_data["Country/Region"] = duplicate_country
    # print(current_country_data)
    confirmed_data = confirmed_data[confirmed_data["Country/Region"] != duplicate_country]
    confirmed_data = confirmed_data.append(current_country_data, ignore_index=True)
confirmed_data
confirmed_data = confirmed_data.T
confirmed_data.columns = confirmed_data.iloc[0]
confirmed_data = confirmed_data.drop(["Country/Region"], axis=0)
confirmed_data
confirmed_data = confirmed_data.reset_index(level=0)
confirmed_data
confirmed_data.columns.values[0] = "Dates"
confirmed_data
confirmed_data = confirmed_data.reset_index(level=0)
confirmed_data
confirmed_data.columns.values[0] = "Day"
confirmed_data
confirmed_data["Dates"] = pd.to_datetime(confirmed_data["Dates"])
confirmed_data<jupyter_output><empty_output><jupyter_text>Plotting Stuff<jupyter_code>x = confirmed_data["Dates"]
y = confirmed_data["Austria"]
plt.plot(x, y, label="Austria")
plt.grid()
plt.title("Austria")
plt.xlabel("Dates")
plt.ylabel("Confirmed cases")
plt.legend()
plt.show()
def clean(df):
    unwanted_cols = ["Province/State", "Lat", "Long"]
    df = df.fillna("")  # handling null cases

    # collapsing provinces
    provinced_locations = df[df.duplicated(["Country/Region"])]
    df = df.drop_duplicates(["Country/Region"])
    for country in provinced_locations["Country/Region"].unique():
        current_country_data = (
            provinced_locations[
                (provinced_locations["Country/Region"] == country)
            ]
            .sum(axis=0)
        )
        current_country_data["Country/Region"] = country
        df = df[df["Country/Region"] != country]
        df = df.append(current_country_data, ignore_index=True)

    df.drop(unwanted_cols, axis=1, inplace=True)
    df = df.T  # transpose

    # columns name as country names
    df.columns = df.iloc[0]
    df = df.drop("Country/Region")

    # The `Date`
    df.reset_index(level=0, inplace=True)
    df.columns.values[0] = "Date"

    # The `Day`
    df.reset_index(level=0, inplace=True)
    df.columns.values[0] = "Day"

    # date type
    df["Date"] = pd.to_datetime(df["Date"])
    return df
death_data = pd.read_csv("data/deaths.csv")
death_data = clean(death_data)
death_data
recovered_data = pd.read_csv("data/recovered.csv")
recovered_data = clean(recovered_data)
recovered_data
# confirmed - recovered - deaths
active_data = pd.DataFrame(columns =["Day", "Dates"])
active_data
confirmed_data = clean(pd.read_csv("data/confirmed.csv"))
confirmed_data
active_data
active_data["Day"] = confirmed_data["Day"]
active_data["Dates"] = confirmed_data["Date"]
active_data
for country in countries:
    active_data[country] = confirmed_data[country] - recovered_data[country] - death_data[country]
active_data
x = active_data["Dates"]
y = active_data["Austria"]
plt.plot(x, y, label="Austria")
plt.grid()
plt.title("Austria")
plt.xlabel("Dates")
plt.ylabel("Confirmed cases")
plt.legend()
plt.show()
austria_peak = active_data.loc[(active_data["Dates"] >= "2020-03-01") & (active_data["Dates"] < "2020-05-01")]
austria_peak
x = austria_peak["Day"]
y = austria_peak["Austria"]
plt.plot(x, y, label="Austria")
plt.grid()
plt.title("Austria")
plt.xlabel("Dates")
plt.ylabel("Confirmed cases")
plt.legend()
plt.xticks(rotation=20)
plt.show()
def gaussian(x, a, b, c):
    from numpy import e
    return a*e**(-(x-b)**2/c)<jupyter_output><empty_output><jupyter_text>Fitting<jupyter_code>from scipy.optimize import curve_fit
popt, error = curve_fit(gaussian, austria_peak["Day"], austria_peak["Austria"], [8000, 70, 1])
gaussian(60, *popt)
fit_x = np.linspace(30, 100, 70)
fit_y = gaussian(fit_x, *popt)
x = austria_peak["Day"]
y = austria_peak["Austria"]
plt.plot(fit_x, fit_y, label="gaussian fit")
plt.plot(x, y, label="data")
plt.xlabel("Dates")
plt.ylabel("Active cases")
plt.legend()
plt.grid()
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14649190439475712, 'fraction_numerical': 0.011757902852737086, 'mean_word_length': 6.370738636363637, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '565450', 'license': 'MIT', 'n_tokens_mistral': 1931, 'n_tokens_neox': 1780, 'n_words': 289, 'path': '01-intro-to-python/day2.ipynb', 'repo_name': 'sdgniser/coding-club-talks', 'size': '5204'}