{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import matplotlib\n",
    "import matplotlib.pyplot as plt\n",
    "# import numpy as np\n",
    "import plotly.express as px\n",
    "covid_data = pd.read_csv('D:/Cloud/Nastya/IT/python/COVID-19-master/csse_covid_19_data/csse_covid_19_daily_reports/04-17-2020.csv')\n",
    "# covid_data2 = pd.read_csv('https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/03-18-2020.csv')\n",
    "ex1 = covid_data.head() # 1ex.\n",
    "ex2 = covid_data.groupby('Country_Region').sum() # 2ex - the latest number of confirmed, deaths, recovered and active cases Country wise\n",
    "# ex3 = covid_data.groupby(['Country_Region', 'Province_State']).sum()[['Deaths','Recovered']] # 3ex - the latest number of confirmed deaths and recovered people Country/Region - Province/State wise\n",
    "# ex4 = covid_data.loc[covid_data['Country_Region']=='China'].groupby(['Province_State']).sum()[['Confirmed','Deaths','Recovered']] # 4ex - the Chinese province wise cases of confirmed, deaths and recovered cases\n",
    "# ex5 = covid_data.groupby('Country_Region').sum()['Deaths'] # 5ex - the latest country wise deaths cases\n",
    "# ex6 = covid_data.loc[covid_data['Recovered']==0].groupby(['Country_Region']) #6ex - list countries with no cases recovered\n",
    "# ex7 = covid_data.loc[(covid_data['Deaths'] == covid_data['Confirmed']) & (covid_data['Confirmed'] > 0)] # 7ex - list countries with all cases died\n",
    "# ex8 = covid_data.loc[(covid_data['Recovered'] == covid_data['Confirmed']) & (covid_data['Confirmed'] > 0)] # 8ex - list countries with all cases recovered\n",
    "# ex9 = covid_data.groupby(['Country_Region']).sum().sort_values(['Confirmed'], ascending=False)[['Confirmed','Deaths','Recovered']].head(10) # 9ex - get the top 10 countries data (Last Update, Country/Region, Confirmed, Deaths, Recovered)\n",
    "\n",
    "### 10ex - create a plot (lines) of total deaths, confirmed, recovered and active cases Country wise where deaths greater than 150\n",
    "table = ex2[['Confirmed','Deaths','Recovered', 'Active']]\n",
    "# countr = table.loc[table['Deaths'] > 50]\n",
    "# countries = [country for country,countr in countr['Confirmed'].items()] # array of cities for graph\n",
    "# plt.figure(figsize=(20,10))\n",
    "# plt.plot(countries, countr['Confirmed'], color='skyblue', linewidth=2, label=\"Confirmed\")\n",
    "# plt.plot(countries, countr['Deaths'], color='red', linewidth=2, label=\"Deaths\")\n",
    "# plt.plot(countries, countr['Recovered'], color='green', linewidth=2, label=\"Recovered\")\n",
    "# plt.plot(countries, countr['Active'],  color='yellow', linewidth=2, label=\"Active\")\n",
    "# plt.legend()\n",
    "# plt.grid()\n",
    "# plt.xticks(countries, rotation='vertical', size=14)\n",
    "# plt.title('Total Deaths(>650), Confirmed, Recovered and Active Cases by Country')\n",
    "# plt.show()\n",
    "\n",
    "### mine\n",
    "# countr['% mortality'] = countr['Deaths'] / countr['Confirmed'] * 100\n",
    "# countr['% recovery'] = countr['Recovered'] / countr['Confirmed'] * 100\n",
    "# countr.sort_values(['% recovery'])\n",
    "\n",
    "### 11ex visualize the state/province wise death cases in USA\n",
    "usa = covid_data.loc[covid_data['Country_Region'] == 'US']\n",
    "usa.drop(index=2840, inplace=True)\n",
    "usa_states = usa.groupby('Province_State').sum()[['Confirmed','Deaths','Recovered', 'Active']]\n",
    "usa_deaths_more = usa_deaths.loc[usa_deaths['Deaths'] > 200]\n",
    "state = [state for state,usa_deaths_more in usa_deaths_more['Deaths'].items()] # array of cities for graph\n",
    "plt.figure(figsize=(20,10))\n",
    "plt.bar(state, usa_deaths_more['Deaths'], color='skyblue', linewidth=2, label=\"Deaths\")\n",
    "plt.grid()\n",
    "plt.xticks(state, rotation='vertical', size=12)\n",
    "plt.title('Deaths Cases (>100) by States in USA')\n",
    "plt.show()\n",
    "\n",
    "### 12ex visualize the state/province wise Active cases of Novel Coronavirus (COVID-19) in USA\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
