Tracking coronavirus total cases, deaths and new cases in India

A Matplotlib Overview by Vasu Golyan

#collapse

update = summary['updated']
cases = summary['Cases']
new = summary['Cases (+)']
deaths = summary['Deaths']
dnew = summary['Deaths (+)']

overview = '''
<!-- #######  HTML!! #########-->
<h1 style="color: #5e9ca0; text-align: center;">India</h1>
<p style="text-align: center;">Last update: <strong>{update}</strong></p>
<p style="text-align: center;">Confirmed cases:</p>
<p style="text-align: center;font-size:24px;">{cases} (<span style="color: #ff0000;">+{new}</span>)</p>
<p style="text-align: center;">Confirmed deaths:</p>
<p style="text-align: center;font-size:24px;">{deaths} (<span style="color: #ff0000;">+{dnew}</span>)</p>
'''


html = HTML(overview.format(update=update, cases=cases,new=new,deaths=deaths,dnew=dnew))

display(html)

India

Last update: 28th July, 2020

Confirmed cases:

1514800 (+49001)

Confirmed deaths:

34121 (+770)

#collapse
dft_ct_new_cases.head()

14-Mar-20 15-Mar-20 16-Mar-20 17-Mar-20 18-Mar-20 19-Mar-20 20-Mar-20 21-Mar-20 22-Mar-20 23-Mar-20 ... 21-Jul-20 22-Jul-20 23-Jul-20 24-Jul-20 25-Jul-20 26-Jul-20 27-Jul-20 28-Jul-20 dt_today dt_yday
states
Andhra Pradesh 0 0 0 0 0 2 0 2 1 1 ... 4944 6045 7998 8147 7813 7627 6051 7948 0 -7948
Maharashtra 0 18 6 3 3 4 4 12 10 23 ... 8336 10576 9895 9615 9251 9431 7924 7717 0 -7717
Tamil Nadu 0 0 0 0 1 1 0 3 3 3 ... 4965 5849 6472 6785 6988 6986 6993 6972 0 -6972
Karnataka 0 0 1 2 5 1 0 5 6 7 ... 3649 4764 5030 5007 5072 5199 5324 5536 0 -5536
Uttar Pradesh 0 1 0 2 2 3 4 4 2 2 ... 2128 2300 2516 2667 2971 3246 3505 3458 0 -3458

5 rows × 139 columns

#collapse
ax = []
fig = plt.figure(figsize = (16,20))
gs = fig.add_gridspec(n+2, 3)
# gs = fig.add_gridspec(2, 3)
ax1 = fig.add_subplot(gs[0, :])
ef = df.loc['Total'].rename_axis('date').reset_index()
ef['date'] = ef['date'].astype('datetime64[ns]')
ax1.bar(ef.date,ef.Total,alpha=0.3,color='#007acc')
ax1.plot(ef.date,ef.Total , marker="o", color='#007acc')
ax1.xaxis.set_major_locator(mdates.WeekdayLocator())
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%b %d'))
ax1.text(0.02, 0.5,'India daily case count', transform = ax1.transAxes, fontsize=25);
ax1.spines['right'].set_visible(False)
ax1.spines['top'].set_visible(False)

ax2 = fig.add_subplot(gs[1,0])
ef = df.loc['Maharashtra'].rename_axis('date').reset_index()
ef['date'] = ef['date'].astype('datetime64[ns]')

ax2.bar(ef.date, ef.Maharashtra,color = '#007acc',alpha=0.5)
ax2.xaxis.set_major_locator(mdates.WeekdayLocator())
ax2.xaxis.set_major_formatter(mdates.DateFormatter('%b %d'))
ax2.set_xticks(ax2.get_xticks()[::3])
maxyval = ef.Maharashtra.max()
ax2.set_ylim([0,maxyval])
ax2.text(0.05, 0.5,'Maharashtra', transform = ax2.transAxes, fontsize=20);
ax2.spines['right'].set_visible(False)
ax2.spines['top'].set_visible(False)


ax3 = fig.add_subplot(gs[1,1])
ef = df.loc['Tamil Nadu'].rename_axis('date').reset_index()
ef['date'] = ef['date'].astype('datetime64[ns]')
ax3.bar(ef.date, ef['Tamil Nadu'],color = '#007acc',alpha=0.5,)
ax3.xaxis.set_major_locator(mdates.WeekdayLocator())
ax3.xaxis.set_major_formatter(mdates.DateFormatter('%b %d'))
ax3.set_xticks(ax3.get_xticks()[::3])
ax3.text(0.05, 0.5,'Tamil Nadu', transform = ax3.transAxes, fontsize=20);
ax3.spines['right'].set_visible(False)
ax3.spines['top'].set_visible(False)

ax4 = fig.add_subplot(gs[1,2])
ef = df.loc['Delhi'].rename_axis('date').reset_index()
ef['date'] = ef['date'].astype('datetime64[ns]')
ax4.bar(ef.date, ef.Delhi,color = '#007acc',alpha=0.5)
ax4.set_xticks([])
ax4.xaxis.set_major_locator(mdates.WeekdayLocator())
ax4.xaxis.set_major_formatter(mdates.DateFormatter('%b %d'))
ax4.set_xticks(ax4.get_xticks()[::3])
ax4.spines['right'].set_visible(False)
ax4.spines['top'].set_visible(False)

ax4.text(0.05, 0.5,'Delhi', transform = ax4.transAxes, fontsize=20)

for i in range(n):
    
    ax.append(fig.add_subplot(gs[i+2,:]))
    ef = df.iloc[i+3].rename_axis('date').reset_index()
    ef['date'] = ef['date'].astype('datetime64[ns]')
    ax[i].bar(ef.date,ef.iloc[:,-1],color = '#007acc',alpha=0.3)
    ax[i].plot(ef.date,ef.iloc[:,-1],marker='o',color='#007acc')
    ax[i].text(0.02,0.5,f'{ef.columns.values[-1]}',transform = ax[i].transAxes, fontsize = 20);
    ax[i].xaxis.set_major_locator(mdates.WeekdayLocator())
    ax[i].xaxis.set_major_formatter(mdates.DateFormatter('%b %d'))
    ax[i].set_ylim([0,7000])
    ax[i].spines['right'].set_visible(False)
    ax[i].spines['top'].set_visible(False)
plt.tight_layout()

#collapse
print(df_table.to_string(index=False))

                      states   Cases  PCases  Deaths  PDeaths  Cases (+)  Deaths (+)  Fatality Rate
                 Maharashtra  391440  383723   14164    13882       7717         282           3.62
                  Tamil Nadu  227688  220716    3659     3571       6972          88           1.61
                       Delhi  132275  131219    3881     3853       1056          28           2.93
              Andhra Pradesh  110297  102349    1148     1090       7948          58           1.04
                   Karnataka  107001  101465    2064     1962       5536         102           1.93
               Uttar Pradesh   73951   70493    1497     1456       3458          41           2.02
                 West Bengal   62964   60830    1449     1411       2134          38           2.30
                     Gujarat   57982   56874    2372     2348       1108          24           4.09
                   Telangana   57142   55532     480      471       1610           9           0.84
                       Bihar   43591   41111     269      255       2480          14           0.62
                   Rajasthan   38636   37564     644      633       1072          11           1.67
                       Assam   34846   33475      92       90       1371           2           0.26
                     Haryana   32876   32127     406      397        749           9           1.23
              Madhya Pradesh   29217   28589     831      821        628          10           2.84
                      Orissa   28107   26892     189      181       1215           8           0.67
                      Kerala   20895   19728      68       64       1167           4           0.33
           Jammu and Kashmir   18879   18390     333      321        489          12           1.76
                      Punjab   14378   13769     336      318        609          18           2.34
                   Jharkhand    9563    8803      94       90        760           4           0.98
                         Goa    5287    5119      36       36        168           0           0.68
                     Tripura    4287    4066      21       17        221           4           0.49
                 Pondicherry    3013    2874      47       43        139           4           1.56
            Himachal Pradesh    2330    2270      13       13         60           0           0.56
                     Manipur    2317    2286       0        0         31           0           0.00
                    Nagaland    1460    1385       4        5         75           0           0.27
           Arunachal Pradesh    1330    1239       3        3         91           0           0.23
                  Chandigarh     934     910      14       14         24           0           1.50
                   Meghalaya     779     738       5        5         41           0           0.64
                      Sikkim     592     568       1        1         24           0           0.17
                     Mizoram     384     361       0        0         23           0           0.00
 Andaman and Nicobar Islands     359     334       1        1         25           0           0.28
               Daman and Diu       0       0       0        0          0           0            NaN
                 Lakshadweep       0       0       0        0          0           0            NaN