w3resource

Python Exercise: Get the Chinese province wise cases of confirmed, deaths and recovered cases of Novel Coronavirus

Python Project: COVID-19 Exercise-4 with Solution

Write a Python program to get the Chinese province wise cases of confirmed, deaths and recovered 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')
c_data = covid_data[covid_data['Country/Region']=='China']
c_data = c_data[['Province/State', 'Confirmed', 'Deaths', 'Recovered']]
result = c_data.sort_values(by='Confirmed', ascending=False)
result = result.reset_index(drop=True)
print(result)

Sample Output:

Dataset information:
<class 'pandas.core.frame.DataFrame'>
    Province/State  Confirmed  Deaths  Recovered
0            Hubei      67799    3111      56003
1        Guangdong       1364       8       1307
2            Henan       1273      22       1250
3         Zhejiang       1232       1       1216
4            Hunan       1018       4       1014
5            Anhui        990       6        984
6          Jiangxi        935       1        934
7         Shandong        761       7        746
8          Jiangsu        631       0        631
9        Chongqing        576       6        570
10         Sichuan        540       3        520
11    Heilongjiang        482      13        456
12         Beijing        456       8        369
13        Shanghai        358       3        325
14           Hebei        318       6        310
15          Fujian        296       1        295
16         Guangxi        253       2        248
17         Shaanxi        246       3        236
18          Yunnan        176       2        172
19          Hainan        168       6        161
20       Hong Kong        162       4         88
21         Guizhou        147       2        144
22         Tianjin        136       3        133
23           Gansu        133       2         91
24          Shanxi        133       0        133
25        Liaoning        125       1        120
26           Jilin         93       1         92
27        Xinjiang         76       3         73
28  Inner Mongolia         75       1         73
29         Ningxia         75       0         75
30         Qinghai         18       0         18
31           Macau         12       0         10
32           Tibet          1       0          1

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 latest number of confirmed deaths and recovered people of Novel Coronavirus (COVID-19) cases Country/Region - Province/State wise.
Next: Write a Python program to get the latest country wise deaths cases of Novel Coronavirus (COVID-19).

What is the difficulty level of this exercise?



Follow us on Facebook and Twitter for latest update.