w3resource

Python Exercise: Latest number of confirmed deaths and recovered people of Novel Coronavirus cases Country wise

Python Project: COVID-19 Exercise-3 with Solution

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.

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-16-2020.csv')
data = covid_data.groupby(['Country/Region', 'Province/State'])['Confirmed', 'Deaths', 'Recovered'].max()
pd.set_option('display.max_rows', None)
print(data)

Sample Output:

Dataset information:
<class 'pandas.core.frame.DataFrame'>
                                             Confirmed  Deaths  Recovered
Country/Region Province/State                                            
Australia      Australian Capital Territory          2       0          0
               From Diamond Princess                 0       0          0
               New South Wales                     210       4          4
               Northern Territory                    1       0          0
               Queensland                           78       0          8
               South Australia                      29       0          3
               Tasmania                              7       0          0
               Victoria                             94       0          8
               Western Australia                    31       1          0
Canada         Alberta                              74       0          0
               British Columbia                    103       4          4
               Grand Princess                        8       0          0
               Manitoba                              8       0          0
               New Brunswick                         8       0          0
               Newfoundland and Labrador             3       0          0
               Nova Scotia                           7       0          0
               Ontario                             185       1          5
               Prince Edward Island                  1       0          0
               Quebec                               74       0          0
               Saskatchewan                          7       0          0
China          Anhui                               990       6        984
               Beijing                             456       8        369
               Chongqing                           576       6        570
               Fujian                              296       1        295
               Gansu                               133       2         91
               Guangdong                          1364       8       1307
               Guangxi                             253       2        248
               Guizhou                             147       2        144
               Hainan                              168       6        161
               Hebei                               318       6        310
               Heilongjiang                        482      13        456
               Henan                              1273      22       1250
               Hong Kong                           162       4         88
               Hubei                             67799    3111      56003
               Hunan                              1018       4       1014
               Inner Mongolia                       75       1         73
               Jiangsu                             631       0        631
               Jiangxi                             935       1        934
               Jilin                                93       1         92
               Liaoning                            125       1        120
               Macau                                12       0         10
               Ningxia                              75       0         75
               Qinghai                              18       0         18
               Shaanxi                             246       3        236
               Shandong                            761       7        746
               Shanghai                            358       3        325
               Shanxi                              133       0        133
               Sichuan                             540       3        520
               Tianjin                             136       3        133
               Tibet                                 1       0          1
               Xinjiang                             76       3         73
               Yunnan                              176       2        172
               Zhejiang                           1232       1       1216
Cruise Ship    Diamond Princess                    696       7        325
Denmark        Denmark                             977       4          1
               Faroe Islands                        47       0          0
France         France                             7652     148         12
               French Guiana                         7       0          0
               French Polynesia                      3       0          0
               Guadeloupe                            6       0          0
               Mayotte                               1       0          0
               Reunion                               9       0          0
               Saint Barthelemy                      3       0          0
               St Martin                             2       0          0
Netherlands    Curacao                               3       0          0
               Netherlands                        1705      43          2
US             Alabama                              39       0          0
               Alaska                                3       0          0
               Arizona                              20       0          1
               Arkansas                             22       0          0
               California                          698      12          6
               Colorado                            160       2          0
               Connecticut                          68       0          0
               Delaware                             16       0          0
               Diamond Princess                     47       0          0
               District of Columbia                 22       0          0
               Florida                             216       6          0
               Georgia                             146       1          0
               Grand Princess                       21       0          0
               Guam                                  3       0          0
               Hawaii                               10       0          0
               Idaho                                 8       0          0
               Illinois                            161       1          2
               Indiana                              30       2          0
               Iowa                                 23       0          0
               Kansas                               18       1          0
               Kentucky                             26       1          1
               Louisiana                           196       4          0
               Maine                                32       0          0
               Maryland                             60       0          3
               Massachusetts                       218       0          1
               Michigan                             65       0          0
               Minnesota                            60       0          0
               Mississippi                          21       0          0
               Missouri                             11       0          0
               Montana                               9       0          0
               Nebraska                             21       0          0
               Nevada                               56       1          0
               New Hampshire                        26       0          0
               New Jersey                          267       3          1
               New Mexico                           23       0          0
               New York                           1706      13          0
               North Carolina                       64       0          0
               North Dakota                          3       0          0
               Ohio                                 67       0          0
               Oklahoma                             19       0          0
               Oregon                               66       1          0
               Pennsylvania                        112       0          0
               Puerto Rico                           5       0          0
               Rhode Island                         23       0          0
               South Carolina                       47       1          0
               South Dakota                         11       1          0
               Tennessee                            74       0          0
               Texas                               110       1          0
               Utah                                 51       0          0
               Vermont                              12       0          0
               Virgin Islands                        2       0          0
               Virginia                             67       2          0
               Washington                         1076      55          1
               West Virginia                         1       0          0
               Wisconsin                            72       0          1
               Wyoming                              11       0          0
United Kingdom Cayman Islands                        1       1          0
               Channel Islands                       6       0          0
               Gibraltar                             3       0          1
               United Kingdom                     1950      55         52

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, recovered and active cases of Novel Coronavirus (COVID-19) Country wise.
Next: Write a Python program to get the Chinese province wise cases of confirmed, deaths and recovered cases of Novel Coronavirus (COVID-19).

What is the difficulty level of this exercise?


Python: Tips of the Day

Converts a string to camelcase

Example:

from re import sub

def tips_camel(x):
  x = sub(r"(_|-)+", " ", x).title().replace(" ", "")
  return x[0].lower() + x[1:]

print(tips_camel('the_quick_brown_fox'))
print(tips_camel('The quick brown fox jumps over lazy'))
print(tips_camel('python-tutorial'))
print(tips_camel('pack-my_box with five_dozen-liquor-jugs'))

Output:

theQuickBrownFox
theQuickBrownFoxJumpsOverLazy
pythonTutorial
packMyBoxWithFiveDozenLiquorJugs