Skip to content

Instantly share code, notes, and snippets.

@siddydutta
Created April 19, 2020 04:08
Show Gist options
  • Save siddydutta/422ea5ab59179a97058c330a4962c0ec to your computer and use it in GitHub Desktop.
Save siddydutta/422ea5ab59179a97058c330a4962c0ec to your computer and use it in GitHub Desktop.
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
raw_data = pd.read_csv('data.csv',encoding='latin1',thousands=',')
# Top 5 Countries Affected
data = raw_data[['Country,Other','TotalCases','TotalDeaths','TotalRecovered']]
most_affected = data.sort_values('TotalCases', ascending=False)[:5]
plt.figure(figsize=(10,5))
sns.barplot(data = most_affected, x = 'Country,Other', y = 'TotalCases',
color='blue')
plt.title('Top Five Countries Affected')
plt.xlabel('Country')
plt.ylabel('Total Number of Cases')
plt.show()
# Comparative Situation of USA With Other Countries
comparision = pd.melt(most_affected, id_vars='Country,Other',
var_name='Metrics',value_name='Counts')
sns.catplot(x='Country,Other', y='Counts', hue='Metrics', data=comparision,
kind='bar')
plt.title('Comparision Among Most Affected')
plt.xlabel('Country')
plt.ylabel('Count')
plt.show()
# Worst Death Rates - Top Ten Countries
data = raw_data[['Country,Other','TotalCases','TotalDeaths']]
data['DeathRate'] = (data['TotalDeaths']/data['TotalCases'])*100
dr = data.sort_values('DeathRate', ascending=False)[:10]
plt.figure(figsize=(13,5))
sns.barplot(data = dr, x = 'Country,Other', y = 'DeathRate',
color='blue')
plt.title('Worst Death Rates - Top Ten Countries')
plt.xlabel('Country')
plt.ylabel('Total Deaths')
plt.show()
# Best Recovery Rates - Top Ten Countries
data = raw_data[['Country,Other','TotalCases','TotalRecovered']]
data['RecoveryRate'] = (data['TotalRecovered']/data['TotalCases'])*100
rr = data.sort_values('RecoveryRate', ascending=False)[:10]
plt.figure(figsize=(13,5))
sns.barplot(data = rr, x = 'Country,Other', y = 'RecoveryRate',
color='blue')
plt.title('Best Recovery Rates - Top Ten Countries')
plt.xlabel('Country')
plt.ylabel('Total Recovered')
plt.show()
# Confirmed Cases - Continents
data = raw_data[['TotalCases', 'Continent']]
continent_data = data.groupby('Continent')['TotalCases'].sum()
continent_data.plot(kind='pie')
plt.title('Confirmed Cases Grouped By Continents')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment