Difference makes the DIFFERENCE
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
plt.style.use(['dark_background'])
import seaborn as sns
sns.set(color_codes = True)
import json
import urllib.request
url = 'https://api.covid19india.org/states_daily.json'
urllib.request.urlretrieve(url, 'data.json')
with open('data.json') as f:
data = json.load(f)
data = data['states_daily']
df = pd.json_normalize(data)
df.drop('dateymd', inplace=True, axis=1)
df.drop('tt', inplace = True, axis=1)
df.head(2)
df_ = df[['mh', 'date', 'status']]
df_.head(2)
df_['mh'] = pd.to_numeric(df_['mh'])
df_['date'] = pd.to_datetime(df_['date'])
df_ = df_.pivot_table(index='date', columns='status', values='mh')
df_.head()
df_.plot()
df_.plot.area();
plt.stackplot(df_.index, df_.Confirmed, df_.Recovered, df_.Deceased)
fig = plt.gcf()
fig.set_size_inches(15, 6)
plt.stackplot(df_.index, df_.Confirmed, df_.Recovered, df_.Deceased,
colors = ['orange', 'green', 'red'])
fig = plt.gcf()
fig.set_size_inches(15, 6)
plt.stackplot(df_.index, df_.Confirmed, df_.Recovered, df_.Deceased,
labels = ['Confirmed', 'Recovered', "Deceased"],
colors = ['orange', 'green', 'red'])
plt.legend()
fig = plt.gcf()
fig.set_size_inches(15, 6)
plt.stackplot(df_.index, df_.Confirmed/df_.sum(axis=1),
df_.Recovered/df_.sum(axis=1),
df_.Deceased/df_.sum(axis=1),
labels = ['Confirmed', 'Recovered', "Deceased"],
colors = ['orange', 'green', 'red']);
plt.legend()
df__ = df_[df_ < 0] = 0
df_.head()
def plot_stackedarea_bystate(state):
df_ = df[[state, 'date', 'status']]
df_[state] = pd.to_numeric(df_[state])
df_['date'] = pd.to_datetime(df_['date'])
df_ = df_.pivot_table(values = state, columns = 'status', index='date')
fig = plt.gcf()
fig.set_size_inches(15, 6)
plt.stackplot(df_.index, df_.Confirmed/df_.sum(axis=1),
df_.Recovered/df_.sum(axis=1),
df_.Deceased/df_.sum(axis=1),
labels = ['Confirmed', 'Recovered', "Deceased"],
colors = ['orange', 'green', 'red']);
plt.legend()
df_.head()
plot_stackedarea_bystate('tn')
plot_stackedarea_bystate('wb')
plot_stackedarea_bystate('dl')
!pip install nbconvert
%shell jupyter nbconvert --to html /content/dvp2_barplots.ipynb