text_html_output_1.png
from plotly.subplots import make_subplots

import numpy as np

import numpy as np # linear algebra

import pandas as pd

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import plotly.express as px

import plotly.express as px

import requests

import requests
url = 'https://www.worldometers.info/coronavirus/#countries'
header = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.75 Safari/537.36', 'X-Requested-With': 'XMLHttpRequest'}
r = requests.get(url, headers=header)
dfs = pd.read_html(r.text)
df = dfs[0]
time_series = pd.read_csv('../input/corona-virus-report/covid_19_clean_complete.csv', parse_dates=['Date'])

df.isnull().sum()

df.rename(columns={'Country,Other': 'Country'}, inplace=True)
df.rename(columns={'Serious,Critical': 'Serious'}, inplace=True)
df.rename(columns={'Tot Cases/1M pop': 'TotalCases/1M'}, inplace=True)
time_series.rename(columns={'Country/Region': 'Country'}, inplace=True)
df.drop('#', axis=1, inplace=True)

time_series.drop('Province/State', axis=1, inplace=True)

df.dtypes

df['TotalCases'] = df['TotalCases'].fillna(0).astype('int')
df['TotalDeaths'] = df['TotalDeaths'].fillna(0).astype('int')
df['TotalRecovered'] = df['TotalRecovered'].fillna(0).astype('int')
df['ActiveCases'] = df['ActiveCases'].fillna(0).astype('int')
df['Serious'] = df['Serious'].fillna(0).astype('int')
df['Deaths/1M pop'] = df['Deaths/1M pop'].fillna(0).astype('int')
df['TotalTests'] = df['TotalTests'].fillna(0).astype('int')
df['Tests/ 1M pop'] = df['Tests/ 1M pop'].fillna(0).astype('int')
df['NewCases'] = df['NewCases'].fillna(0)
df[['NewCases']] = df[['NewCases']].replace('[\\+,]', '', regex=True).astype(int)
df['NewDeaths'] = df['NewDeaths'].fillna(0)
df[['NewDeaths']] = df[['NewDeaths']].replace('[\\+,]', '', regex=True).astype(int)
df[['Population']] = df[['Population']].fillna(0).astype('int')
time_series.fillna(0)
time_series.isnull().sum()

dataframe = df.iloc[1:216, :-1]
dataframe.style.background_gradient(cmap='Reds')

group1 = time_series.groupby(['Date', 'Country'])['Confirmed', 'Deaths', 'Recovered'].sum().reset_index()
heat = px.choropleth(group1, locations='Country', locationmode='country names', color=np.log(group1['Confirmed']), hover_name='Country', projection='natural earth', title='Heatmap', color_continuous_scale=px.colors.sequential.Blues)
heat.update(layout_coloraxis_showscale=False)

fig_heat = px.choropleth(group1, locations='Country', locationmode='country names', color=np.log(group1['Deaths']), hover_name='Country', projection='natural earth', title='Heatmap(Deaths)', color_continuous_scale=px.colors.sequential.Reds)
fig_heat.update(layout_coloraxis_showscale=False)

fig_z = px.bar(dataframe.sort_values('TotalCases'),x='TotalCases', y='Country',orientation = 'h',

            color_discrete_sequence=['#B3611A'],text = 'TotalCases',title='TotalCases')

fig_x = px.bar(dataframe.sort_values('TotalDeaths'),x='TotalDeaths', y='Country',orientation = 'h',
               color_discrete_sequence=['#830707'],text = 'TotalDeaths',title = 'TotalDeaths')

fig_ = px.bar(dataframe.sort_values('TotalRecovered'),x='TotalRecovered',y='Country',orientation ='h',
               color_discrete_sequence=['#073707'],text = 'TotalRecovered',title = 'TotalRecovered')

fig_p = make_subplots(rows =1,cols =3,subplot_titles=('TotalCases','TotalDeaths','TotalRecovered'))

fig_p.add_trace(fig_z['data'][0],row = 1,col =1)
fig_p.add_trace(fig_x['data'][0],row = 1,col =2)
fig_p.add_trace(fig_['data'][0],row=1,col=3)

fig_p.update_layout(height=3000,title ='Per Country')
fig_p.show()

totalCases = df.iloc[1:21, 0:2]
df1 = df[['Country', 'TotalDeaths']]
TotalDeaths = df1[1:21]
df2 = df[['Country', 'TotalRecovered']]
totalrecovered = df2[1:21]

data = totalCases.sort_values('TotalCases')
data1 = TotalDeaths.sort_values('TotalDeaths')
data2 = totalrecovered.sort_values('TotalRecovered')
fig1 = px.bar(data, x='TotalCases', y='Country', orientation='h', color_discrete_sequence=['#B3611A'], text='TotalCases')
fig2 = px.bar(data1, x='TotalDeaths', y='Country', orientation='h', color_discrete_sequence=['#830707'], text='TotalDeaths')
fig3 = px.bar(data2, x='TotalRecovered', y='Country', orientation='h', color_discrete_sequence=['#073707'], text='TotalRecovered')
fig = make_subplots(rows=2, cols=3, subplot_titles=('Totalconfirmed', 'Total deaths', 'total Recovered'))
fig.add_trace(fig1['data'][0], row=1, col=1)
fig.add_trace(fig2['data'][0], row=1, col=2)
fig.add_trace(fig3['data'][0], row=1, col=3)
fig.update_layout(height=1200, title='Top 20 Countries')
fig.show()