Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

Python Exercise: Get the latest country wise deaths cases of Novel Coronavirus

Python Project: COVID-19 Exercise-5 with Solution

Write a Python program to get the latest country wise deaths cases of Novel Coronavirus (COVID-19).

Sample Solution:

Python Code:

import pandas as pd
covid_data= pd.read_csv('https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/03-17-2020.csv')
data = covid_data.groupby('Country/Region')['Confirmed', 'Deaths', 'Recovered'].sum().reset_index()
result = data[data['Deaths']>0][['Country/Region', 'Deaths']]
print(result)

Sample Output:

Dataset information:
<class 'pandas.core.frame.DataFrame'>
         Country/Region  Deaths
1               Albania       1
2               Algeria       4
5             Argentina       2
8             Australia       5
9               Austria       3
10           Azerbaijan       1
11              Bahrain       1
15              Belgium      10
20               Brazil       1
22             Bulgaria       2
26               Canada       5
29                China    3230
36          Cruise Ship       7
40              Denmark       4
41   Dominican Republic       1
42              Ecuador       2
43                Egypt       4
49               France     148
53              Germany      24
55               Greece       5
59            Guatemala       1
62               Guyana       1
65              Hungary       1
66              Iceland       1
67                India       3
68            Indonesia       5
69                 Iran     988
70                 Iraq      11
71              Ireland       2
73                Italy    2503
75                Japan      29
80         Korea, South      81
84              Lebanon       3
88           Luxembourg       1
89             Malaysia       2
92           Martinique       1
100             Morocco       2
103         Netherlands      43
107              Norway       3
110              Panama       1
113         Philippines      12
114              Poland       5
115            Portugal       1
125          San Marino       7
132            Slovenia       1
135               Spain     533
137               Sudan       1
139              Sweden       7
140         Switzerland      27
141             Taiwan*       1
143            Thailand       1
149              Turkey       1
150                  US     108
151             Ukraine       2
153      United Kingdom      56

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program to get the Chinese province wise cases of confirmed, deaths and recovered cases of Novel Coronavirus (COVID-19).
Next: Write a Python program to list countries with no cases of Novel Coronavirus (COVID-19) recovered.

What is the difficulty level of this exercise?



Python: Tips of the Day

Find current directory and file's directory:

To get the full path to the directory a Python file is contained in, write this in that file:

import os 
dir_path = os.path.dirname(os.path.realpath(__file__))

(Note that the incantation above won't work if you've already used os.chdir() to change your current working directory, since the value of the __file__ constant is relative to the current working directory and is not changed by an os.chdir() call.)

To get the current working directory use

import os
cwd = os.getcwd()

Documentation references for the modules, constants and functions used above:

  • The os and os.path modules.
  • The __file__ constant
  • os.path.realpath(path) (returns "the canonical path of the specified filename, eliminating any symbolic links encountered in the path")
  • os.path.dirname(path) (returns "the directory name of pathname path")
  • os.getcwd() (returns "a string representing the current working directory")
  • os.chdir(path) ("change the current working directory to path")

Ref: https://bit.ly/3fy0R6m