﻿ Python Project: Get the latest country wise deaths cases of Novel Coronavirus - 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
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
29                China    3230
36          Cruise Ship       7
40              Denmark       4
41   Dominican Republic       1
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.

What is the difficulty level of this exercise?

﻿

## Python: Tips of the Day

Decompose a collection:

Assume we have a function that returns a tuple of two values and we want to assign each value to a separate variable. One way is to use indexing as below:

```abc = (5, 10)
x = abc[0]
y = abc[1]
print(x, y)
```

Output:

```5 10
```

There is a better option that allows us to do the same operation in one line.

```x, y = abc
print(x, y)

```

Output:

```5 10
```

It can be extended to a tuple with more than 2 values or some other data structures such as lists or sets.

```x, y, z = {1, 2, 3}
print(x, y, z)
x, y, z = ['a', 'b', 'c']
print(x, y, z)
```

Output:

```1 2 3
a b c
```