<jupyter_start><jupyter_text>Ghi chú:Data về dân số TG: https://worldpopulationreview.com/Data về vaccine và COVID-19: Trường ĐH Johns Hopkins - Centers for Civic Impact (https://civicimpact.jhu.edu/)Viết bởi vupa 20210531<jupyter_code>path_covid = "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv"

df = pd.read_csv(path, parse_dates=True)
df.head()
# melt cot lai - tidy data
df_covid = df.melt(id_vars=['Province/State', 'Country/Region', 'Lat', 'Long'], var_name='Date')

df_covid = df_covid[['Country/Region', 'Date', 'value']]

df_coid['Date'] = pd.to_datetime(df_covid['Date'])

path_population = "https://raw.githubusercontent.com/vuanhpham/VUPA_PUB/main/csvData_WorldPopulation.csv"
path_vaccine = "https://raw.githubusercontent.com/govex/COVID-19/master/data_tables/vaccine_data/global_data/time_series_covid19_vaccine_global.csv"
df_pop = pd.read_csv(path_population, parse_dates=True)
df_vaccine = pd.read_csv(path_vaccine, parse_dates=True)
# population toi 2018
df_pop = df_pop[['cca2', 'name', 'pop2021']]
df_pop[df_pop['name'] =='Vietnam']
# sanity check
df_vaccine = df_vaccine[['Country_Region', 'People_partially_vaccinated', 'Date']]
df_vaccine2 = df_vaccine.groupby(['Date', 'Country_Region'])[['People_partially_vaccinated']]\
    .sum()\
    .reset_index()    
df_vaccine3 = pd.merge(df_vaccine2, df_pop, left_on= 'Country_Region', right_on='name', how='left')\
    [['Date', 'Country_Region', 'People_partially_vaccinated', 'pop2021']]
    
df_vaccine3.dropna(subset = ["pop2021"], inplace=True)

# tinh % dan so duoc tiem vaccine, so vaccinated la cumsum
df_vaccine3['pct_vaccinated_pop'] = (df_vaccine3['People_partially_vaccinated'].div(1000))\
    .div(df_vaccine3['pop2021']).mul(100).round(2)

# index date 
df_vaccine3['Date'] = pd.to_datetime(df_vaccine3['Date'])
df_vaccine3  = df_vaccine3.set_index('Date')

# top 30 nuoc co ti le chich vaccine cao
df_top_30_vaccine_countries = df_vaccine3['2021-05'].sort_values(by='pct_vaccinated_pop', ascending=False)\
      .drop_duplicates(subset=['Country_Region'])\
      .head(30)<jupyter_output><empty_output><jupyter_text>30 nước có tỷ lệ vaccine cao nhất (ít nhất 1 liều)<jupyter_code>df_top_30_vaccine_countries['rank'] = df_top_30_vaccine_countries['pct_vaccinated_pop'].rank(ascending=False)
df_top_30_vaccine_countries<jupyter_output><empty_output><jupyter_text>Số ca tử vong trong 1 tuần năm 2021:  Việt Nam vs một số nước có tỉ lệ vaccine cao trong top 30 (ít nhất 1 liều)<jupyter_code>topCountries= ['Israel', 'United Kingdom', 'United Arab Emirates', 'Germany', 'Italy', 'Singapore']
dfx = df_covid.groupby(['Date', 'Country/Region'])['value'].sum()\
    .unstack('Country/Region')[['Vietnam'] + topCountries]
# death here is cumsum value

# death on daily basis 
# recaculate from cumsum
dfx = dfx - dfx.tshift(1)
dfx = dfx.fillna(0)
# tinh so death moi ngay, break ra tu so cumsum

dfy = dfx.resample('W').sum()['2021']#.plot(figsize=(18, 8))
dfy[:-1]<jupyter_output><empty_output><jupyter_text>Chart nước Anh, Đức, Ý và IsraelVaccine giúp kéo giảm nhanh số lượng ca tử vong<jupyter_code># ve chart the country
def plot_chart(country):
    df_tmp = df_vaccine3['2021'].sort_values(by='pct_vaccinated_pop', ascending=False)
    df_tmp = df_tmp[df_tmp['Country_Region']==country].resample('W').ffill()[['pct_vaccinated_pop']]

    # bo line cuoi - vi chua full week, số là 0
    df_table = dfy[[country]].join(df_tmp)[:-1]
    days_bar = df_table.index

    # normalize cai cot y
    ct_norm = df_table['pct_vaccinated_pop']/df_table['pct_vaccinated_pop'].max() * df_table[country].values.max()
    ct_bar = df_table.loc[days_bar]['pct_vaccinated_pop']
    ct_bar_norm = ct_norm.loc[days_bar]

    fig, ax = plt.subplots(1, 1, figsize=(18, 8), linewidth=2, edgecolor='.5')
    ax.plot(
        df_table.index.values, df_table[country].values, 
        linestyle='--', linewidth=2, color='.2', label='Number deaths per week')

    ax.bar(x=days_bar, height=ct_bar_norm, width = 4, facecolor='0.5', alpha=.3, label='Vaccination rates')

    for x, y, t in zip(days_bar, ct_bar_norm, ct_bar):
        ax.text(x, y+.6, "{percent}%".format(percent=t), ha='center')
 
    plt.title('Country: ' + country)
    plt.legend()
for country in ['Israel', 'United Kingdom', 'Germany', 'Italy']:
    plot_chart(country)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1524197195838987, 'fraction_numerical': 0.027815468113975575, 'mean_word_length': 6.020634920634921, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 5, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '657445', 'license': 'MIT', 'n_tokens_mistral': 1893, 'n_tokens_neox': 1738, 'n_words': 307, 'path': '20210530_COVID19_VACCINE_EDA.ipynb', 'repo_name': 'vuanhpham/VUPA_PUB', 'size': '4422'}