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?



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/python-exercises/project/covid-19/python-covid-19-exercise-5.php