w3resource

Python Exercise: Display first 5 rows from COVID-19 dataset

Python Project: COVID-19 Exercise-1 with Solution

Write a Python program to display first 5 rows from COVID-19 dataset. Also print the dataset information and check the missing values.

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')
print(covid_data)
print("\nDataset information:")
print(covid_data.info())
print("\nMissing data information:")
print(covid_data.isna().sum())

Sample Output:

Dataset information:
<class 'pandas.core.frame.DataFrame'>
                   Province/State  ... Longitude
0                           Hubei  ...  112.2707
1                             NaN  ...   12.5674
2                             NaN  ...   53.6880
3                             NaN  ...   -3.7492
4                             NaN  ...   10.4515
5                             NaN  ...  127.7669
6                          France  ...    2.2137
7                             NaN  ...    8.2275
8                  United Kingdom  ...   -3.4360
9                        New York  ...  -74.9481
10                    Netherlands  ...    5.2913
11                            NaN  ...    8.4689
12                      Guangdong  ...  113.4244
13                            NaN  ...   14.5501
14                          Henan  ...  113.6140
15                            NaN  ...    4.4699
16                       Zhejiang  ...  120.0934
17                            NaN  ...   18.6435
18                     Washington  ... -121.4905
19                          Hunan  ...  111.7088
20                          Anhui  ...  117.2264
21                        Denmark  ...    9.5018
22                        Jiangxi  ...  115.7221
23                            NaN  ...  138.2529
24                       Shandong  ...  118.1498
25                     California  ... -119.6816
26               Diamond Princess  ...  139.6649
27                            NaN  ...  101.9758
28                        Jiangsu  ...  119.4550
29                      Chongqing  ...  107.8740
30                        Sichuan  ...  102.7103
31                   Heilongjiang  ...  127.7615
32                        Beijing  ...  116.4142
33                            NaN  ...   -8.2245
34                            NaN  ...   51.1839
35                            NaN  ...   15.4730
36                            NaN  ...   21.8243
37                       Shanghai  ...  121.4491
38                            NaN  ...   34.8516
39                            NaN  ...  -51.9253
40                            NaN  ...   25.7482
41                          Hebei  ...  114.5149
42                         Fujian  ...  117.9874
43                            NaN  ...   14.9955
44                     New Jersey  ...  -74.5210
45                            NaN  ...  103.8198
46                        Guangxi  ...  108.7881
47                        Shaanxi  ...  108.8701
48                            NaN  ...   19.1451
49                            NaN  ...   69.3451
50                            NaN  ...   50.5577
51                            NaN  ...   25.0136
52                            NaN  ...   -7.6921
53                            NaN  ...  -19.0208
54                  Massachusetts  ...  -71.5301
55                        Florida  ...  -81.6868
56                New South Wales  ...  151.2093
57                            NaN  ...  -71.5430
58                            NaN  ...   30.8025
59                      Louisiana  ...  -91.8678
60                            NaN  ...  121.7740
61                        Ontario  ...  -85.3232
62                            NaN  ...   24.9668
63                            NaN  ...  100.9925
64                         Yunnan  ...  101.4870
65                            NaN  ...  113.9213
66                            NaN  ...   45.0792
67                         Hainan  ...  109.7453
68                      Hong Kong  ...  114.2000
69                       Illinois  ...  -88.9861
70                       Colorado  ... -105.3111
71                            NaN  ...   43.6793
72                        Guizhou  ...  106.8748
73                        Georgia  ...  -83.6431
74                            NaN  ...   78.9629
75                            NaN  ...    6.1296
76                        Tianjin  ...  117.3230
77                          Gansu  ...  103.8343
78                         Shanxi  ...  112.2922
79                            NaN  ...   47.4818
80                       Liaoning  ...  122.6085
81                            NaN  ...   35.8623
82                            NaN  ...  -75.0152
83                            NaN  ...  105.3188
84                   Pennsylvania  ...  -77.2098
85                          Texas  ...  -97.5635
86                            NaN  ...   12.4578
87               British Columbia  ... -127.6476
88                            NaN  ...   53.8478
89                       Victoria  ...  144.9631
90                          Jilin  ...  126.1923
91                            NaN  ... -102.5528
92                            NaN  ...   45.0382
93                     Queensland  ...  153.4000
94                            NaN  ...  121.0000
95                       Xinjiang  ...   85.2401
96                 Inner Mongolia  ...  113.9448
97                        Ningxia  ...  106.1655
98                        Alberta  ... -116.5765
99                         Quebec  ...  -73.5491
100                     Tennessee  ...  -86.6923
101                           NaN  ...   19.6990
102                     Wisconsin  ...  -89.6165
103                           NaN  ...  -80.7821
104                           NaN  ...  -63.6167
105                   Connecticut  ...  -72.7554
106                           NaN  ...   25.4858
107                          Ohio  ...  -82.7649
108                      Virginia  ...  -78.1700
109                        Oregon  ... -122.0709
110                           NaN  ...  108.2772
111                           NaN  ...  -74.2973
112                           NaN  ...   15.2000
113                           NaN  ...   21.0059
114                      Michigan  ...  -84.5361
115                North Carolina  ...  -79.8064
116                           NaN  ...   22.9375
117                           NaN  ...    1.6596
118                      Maryland  ...  -76.8021
119                     Minnesota  ...  -93.9002
120                           NaN  ...  -78.1834
121                           NaN  ...  114.7277
122                        Nevada  ... -117.0554
123                           NaN  ...   20.1683
124                          Utah  ... -111.8624
125                           NaN  ...   19.5033
126                           NaN  ...   24.6032
127                 Faroe Islands  ...   -6.9118
128                           NaN  ...   35.2433
129              Diamond Princess  ...  139.6380
130                South Carolina  ...  -80.9450
131                           NaN  ...   33.4299
132                           NaN  ...   80.7718
133                           NaN  ...  -83.7534
134                           NaN  ...    1.5218
135                       Alabama  ...  -86.9023
136                           NaN  ...   14.3754
137                           NaN  ...   -7.0926
138                           NaN  ...   27.9534
139                           NaN  ...   43.3569
140                           NaN  ...   36.2384
141                           NaN  ...  104.9910
142                           NaN  ...   66.9237
143                           NaN  ...  -66.5897
144                         Maine  ...  -69.3819
145             Western Australia  ...  115.8605
146                           NaN  ...   28.3699
147                       Indiana  ...  -86.2583
148               South Australia  ...  138.6007
149                           NaN  ...  -55.7658
150                           NaN  ...   47.5769
151                           NaN  ...   17.6791
152                           NaN  ...   21.7453
153                           NaN  ...  -14.4524
154                      Kentucky  ...  -84.6701
155                 New Hampshire  ...  -71.5639
156                           NaN  ...   23.8813
157                           NaN  ...   55.9754
158                           NaN  ...    9.5375
159                          Iowa  ...  -93.2105
160                    New Mexico  ... -106.2485
161                  Rhode Island  ...  -71.5118
162                           NaN  ...   67.7100
163                      Arkansas  ...  -92.3731
164          District of Columbia  ...  -77.0268
165                           NaN  ...  -70.1627
166                Grand Princess  ... -122.6655
167                   Mississippi  ...  -89.6787
168                      Nebraska  ...  -98.2681
169                       Arizona  ... -111.4312
170                      Oklahoma  ...  -96.9289
171                       Qinghai  ...   95.9956
172                           NaN  ...  -61.5510
173                        Kansas  ...  -96.7265
174                           NaN  ...  -61.0242
175                      Delaware  ...  -75.5071
176                           NaN  ...   -1.5616
177                           NaN  ...   31.1656
178                           NaN  ...   73.2207
179                         Macau  ...  113.5500
180                           NaN  ...  -77.2975
181                           NaN  ...  174.8860
182                       Vermont  ...  -72.7107
183                           NaN  ...  -63.5887
184                           NaN  ...  -53.1258
185                      Missouri  ...  -92.2884
186                  South Dakota  ...  -99.4388
187                       Wyoming  ... -107.3025
188                           NaN  ...   90.3563
189                           NaN  ...   11.5021
190                        Hawaii  ... -157.4983
191                           NaN  ...   64.5853
192                       Reunion  ...   55.2471
193                           NaN  ...  -58.4438
194                           NaN  ...   55.5364
195                       Montana  ... -110.4544
196                Grand Princess  ... -122.6655
197                      Manitoba  ...  -98.8139
198                 New Brunswick  ...  -66.4619
199                           NaN  ...  -86.2419
200                         Idaho  ... -114.4788
201                      Tasmania  ...  145.9707
202                   Nova Scotia  ...  -63.7443
203                  Saskatchewan  ... -106.4509
204                 French Guiana  ...  -53.0000
205                           NaN  ...   -1.0232
206                           NaN  ...  -58.9302
207                           NaN  ...    9.5554
208                           NaN  ...    7.4246
209                           NaN  ...   29.8739
210                    Guadeloupe  ...  -61.5833
211                           NaN  ...  -90.2308
212               Channel Islands  ...   -2.3644
213                           NaN  ...   -5.5471
214                           NaN  ...  -77.7812
215                           NaN  ...   40.4897
216                           NaN  ...  103.8467
217                           NaN  ...  -61.2225
218                   Puerto Rico  ...  -66.5901
219                           NaN  ...   55.4920
220                           NaN  ...  -69.9683
221     Newfoundland and Labrador  ...  -57.6604
222                           NaN  ...   21.7587
223              French Polynesia  ... -149.4068
224              Saint Barthelemy  ...  -62.8333
225                           NaN  ...  144.7937
226                           NaN  ...   37.9062
227                       Curacao  ...  -68.9900
228                           NaN  ...    8.6753
229                        Alaska  ... -152.4044
230                          Guam  ...  144.7937
231                  North Dakota  ...  -99.7840
232                     Gibraltar  ...   -5.3536
233  Australian Capital Territory  ...  149.0124
234                           NaN  ...  -59.5432
235                     St Martin  ...  -63.0501
236                           NaN  ...   20.9030
237                           NaN  ...   19.3000
238                           NaN  ...   18.4904
239                           NaN  ...  -60.9789
240                Virgin Islands  ...  -64.8963
241                           NaN  ...  -61.7964
242            Northern Territory  ...  130.8456
243                           NaN  ...    2.3158
244                           NaN  ...   90.4336
245          Prince Edward Island  ...  -63.4168
246                           NaN  ...   20.9394
247                         Tibet  ...   88.0924
248                           NaN  ...   15.8277
249                           NaN  ...   10.0000
250                           NaN  ...   31.4659
251                       Mayotte  ...   45.1383
252                           NaN  ...   11.6094
253                           NaN  ...  -42.6043
254                           NaN  ...   -9.6966
255                           NaN  ...   12.4534
256                           NaN  ...   -9.4295
257                           NaN  ...  -10.9408
258                           NaN  ...   45.1662
259                           NaN  ...   84.1240
260                           NaN  ...  -61.2872
261                           NaN  ...   46.1996
262                           NaN  ...   30.2176
263                           NaN  ...  -56.0278
264                           NaN  ...   34.8888
265                           NaN  ...  -76.0000
266                           NaN  ...  -16.6000
267                           NaN  ...    0.8248
268                 West Virginia  ...  -80.9545
269                Cayman Islands  ...  -81.2546
270         From Diamond Princess  ...  139.6380
271                           NaN  ...   -2.5800
272                           NaN  ...   -2.1100
273                           NaN  ...  -66.5000
274                           NaN  ...   15.5560
275                           NaN  ...   35.2332

[276 rows x 8 columns]

Dataset information:

RangeIndex: 276 entries, 0 to 275
Data columns (total 8 columns):
Province/State    126 non-null object
Country/Region    276 non-null object
Last Update       276 non-null object
Confirmed         276 non-null int64
Deaths            276 non-null int64
Recovered         276 non-null int64
Latitude          276 non-null float64
Longitude         276 non-null float64
dtypes: float64(2), int64(3), object(3)
memory usage: 17.4+ KB
None

Missing data information:
Province/State    150
Country/Region      0
Last Update         0
Confirmed           0
Deaths              0
Recovered           0
Latitude            0
Longitude           0
dtype: int64

Python Code Editor:

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

Previous: Python Project Covid-19 Exercise Home.
Next: Write a Python program to get the latest number of confirmed, deaths, recovered and active cases of Novel Coronavirus (COVID-19) Country 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://198.211.115.131/python-exercises/project/covid-19/python-covid-19-exercise-1.php