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?
Python: Tips of the Day
Find current directory and file's directory:
To get the full path to the directory a Python file is contained in, write this in that file:
import os dir_path = os.path.dirname(os.path.realpath(__file__))
(Note that the incantation above won't work if you've already used os.chdir() to change your current working directory, since the value of the __file__ constant is relative to the current working directory and is not changed by an os.chdir() call.)
To get the current working directory use
import os cwd = os.getcwd()
Documentation references for the modules, constants and functions used above:
- The os and os.path modules.
- The __file__ constant
- os.path.realpath(path) (returns "the canonical path of the specified filename, eliminating any symbolic links encountered in the path")
- os.path.dirname(path) (returns "the directory name of pathname path")
- os.getcwd() (returns "a string representing the current working directory")
- os.chdir(path) ("change the current working directory to path")
Ref: https://bit.ly/3fy0R6m
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework