w3resource

Python Exercise: Get the latest number of confirmed, deaths, recovered and active cases of Novel Coronavirus Country wise

Python Project: COVID-19 Exercise-2 with Solution

Write a Python program to get the latest number of confirmed, deaths, recovered and active cases of Novel Coronavirus (COVID-19) Country wise.

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')
covid_data['Active'] = covid_data['Confirmed'] - covid_data['Deaths'] - covid_data['Recovered']
result = covid_data.groupby('Country/Region')['Confirmed', 'Deaths', 'Recovered', 'Active'].sum().reset_index()
print(result) 

Sample Output:

                       Country/Region  Confirmed  Deaths  Recovered  Active
0                         Afghanistan         22       0          1      21
1                             Albania         55       1          0      54
2                             Algeria         60       4         12      44
3                             Andorra         39       0          1      38
4                 Antigua and Barbuda          1       0          0       1
5                           Argentina         68       2          3      63
6                             Armenia         78       0          1      77
7                               Aruba          3       0          0       3
8                           Australia        452       5         23     424
9                             Austria       1332       3          1    1328
10                         Azerbaijan         28       1          6      21
11                            Bahrain        228       1         81     146
12                         Bangladesh         10       0          3       7
13                           Barbados          2       0          0       2
14                            Belarus         36       0          3      33
15                            Belgium       1243      10          1    1232
16                              Benin          1       0          0       1
17                             Bhutan          1       0          0       1
18                            Bolivia         11       0          0      11
19             Bosnia and Herzegovina         26       0          2      24
20                             Brazil        321       1          2     318
21                             Brunei         56       0          0      56
22                           Bulgaria         67       2          0      65
23                       Burkina Faso         15       0          0      15
24                           Cambodia         33       0          1      32
25                           Cameroon         10       0          0      10
26                             Canada        478       5          9     464
27           Central African Republic          1       0          0       1
28                              Chile        201       0          0     201
29                              China      81058    3230      68798    9030
30                           Colombia         65       0          1      64
31                Congo (Brazzaville)          1       0          0       1
32                   Congo (Kinshasa)          3       0          0       3
33                         Costa Rica         41       0          0      41
34                      Cote d'Ivoire          5       0          1       4
35                            Croatia         65       0          4      61
36                        Cruise Ship        696       7        325     364
37                               Cuba          5       0          0       5
38                             Cyprus         46       0          0      46
39                            Czechia        396       0          3     393
40                            Denmark       1024       4          1    1019
41                 Dominican Republic         21       1          0      20
42                            Ecuador         58       2          0      56
43                              Egypt        196       4         32     160
44                  Equatorial Guinea          1       0          0       1
45                            Estonia        225       0          1     224
46                           Eswatini          1       0          0       1
47                           Ethiopia          5       0          0       5
48                            Finland        321       0         10     311
49                             France       7683     148         12    7523
50                      French Guiana         11       0          0      11
51                              Gabon          1       0          0       1
52                            Georgia         34       0          1      33
53                            Germany       9257      24         67    9166
54                              Ghana          7       0          0       7
55                             Greece        387       5          8     374
56                          Greenland          1       0          0       1
57                         Guadeloupe         18       0          0      18
58                               Guam          3       0          0       3
59                          Guatemala          6       1          0       5
60                           Guernsey          0       0          0       0
61                             Guinea          1       0          0       1
62                             Guyana          7       1          0       6
63                           Holy See          1       0          0       1
64                           Honduras          8       0          0       8
65                            Hungary         50       1          2      47
66                            Iceland        220       1          0     219
67                              India        142       3         14     125
68                          Indonesia        172       5          8     159
69                               Iran      16169     988       5389    9792
70                               Iraq        154      11         32     111
71                            Ireland        223       2          5     216
72                             Israel        337       0         11     326
73                              Italy      31506    2503       2941   26062
74                            Jamaica         12       0          2      10
75                              Japan        878      29        144     705
76                             Jersey          0       0          0       0
77                             Jordan         34       0          1      33
78                         Kazakhstan         33       0          0      33
79                              Kenya          3       0          0       3
80                       Korea, South       8320      81       1407    6832
81                             Kosovo          2       0          0       2
82                             Kuwait        130       0          9     121
83                             Latvia         49       0          1      48
84                            Lebanon        120       3          3     114
85                            Liberia          1       0          0       1
86                      Liechtenstein          7       0          0       7
87                          Lithuania         25       0          1      24
88                         Luxembourg        140       1          0     139
89                           Malaysia        673       2         49     622
90                           Maldives         13       0          0      13
91                              Malta         38       0          2      36
92                         Martinique         16       1          0      15
93                         Mauritania          1       0          0       1
94                            Mayotte          1       0          0       1
95                             Mexico         82       0          4      78
96                            Moldova         30       0          1      29
97                             Monaco          7       0          0       7
98                           Mongolia          5       0          0       5
99                         Montenegro          2       0          0       2
100                           Morocco         38       2          1      35
101                           Namibia          2       0          0       2
102                             Nepal          1       0          1       0
103                       Netherlands       1708      43          2    1663
104                       New Zealand         12       0          0      12
105                           Nigeria          3       0          0       3
106                   North Macedonia         26       0          1      25
107                            Norway       1463       3          1    1459
108                              Oman         24       0          9      15
109                          Pakistan        236       0          2     234
110                            Panama         69       1          0      68
111                          Paraguay          9       0          0       9
112                              Peru        117       0          1     116
113                       Philippines        187      12          5     170
114                            Poland        238       5         13     220
115                          Portugal        448       1          3     444
116                       Puerto Rico          0       0          0       0
117                             Qatar        439       0          4     435
118             Republic of the Congo          0       0          0       0
119                           Reunion          9       0          0       9
120                           Romania        184       0         16     168
121                            Russia        114       0          8     106
122                            Rwanda          7       0          0       7
123                       Saint Lucia          2       0          0       2
124  Saint Vincent and the Grenadines          1       0          0       1
125                        San Marino        109       7          4      98
126                      Saudi Arabia        171       0          6     165
127                           Senegal         26       0          2      24
128                            Serbia         65       0          1      64
129                        Seychelles          4       0          0       4
130                         Singapore        266       0        114     152
131                          Slovakia         72       0          0      72
132                          Slovenia        275       1          0     274
133                           Somalia          1       0          0       1
134                      South Africa         62       0          0      62
135                             Spain      11748     533       1028   10187
136                         Sri Lanka         44       0          1      43
137                             Sudan          1       1          0       0
138                          Suriname          1       0          0       1
139                            Sweden       1190       7          1    1182
140                       Switzerland       2700      27          4    2669
141                           Taiwan*         77       1         22      54
142                          Tanzania          1       0          0       1
143                          Thailand        177       1         41     135
144                       The Bahamas          1       0          0       1
145                        The Gambia          1       0          0       1
146                              Togo          1       0          0       1
147               Trinidad and Tobago          5       0          0       5
148                           Tunisia         24       0          0      24
149                            Turkey         47       1          0      46
150                                US       6421     108         17    6296
151                           Ukraine         14       2          0      12
152              United Arab Emirates         98       0         23      75
153                    United Kingdom       1960      56         53    1851
154                           Uruguay         29       0          0      29
155                        Uzbekistan         10       0          0      10
156                         Venezuela         33       0          0      33
157                           Vietnam         66       0         16      50
158    occupied Palestinian territory          0       0          0       0

Python Code Editor:

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

Previous: Write a Python program to display first 5 rows from COVID-19 dataset.
Next: Write a Python program to get the latest number of confirmed deaths and recovered people of Novel Coronavirus (COVID-19) cases Country/Region - Province/State wise.

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://www.w3resource.com/python-exercises/project/covid-19/python-covid-19-exercise-2.php