-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCovid19_Api.py
87 lines (63 loc) · 2.68 KB
/
Covid19_Api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
'''
Author : Dalpat I
'''
import requests
import pandas as pd
from pandas.io.json import json_normalize
import numpy as np
import matplotlib.pyplot as plt
class API_travel:
def travel_exe():
response = requests.get("https://www.trackcorona.live/api/travel")
a = response.json()['data'] #taking only "data" part of json file
df = json_normalize(a) #normalize json format data to dataframe format data
df['data'].replace('', np.nan, inplace=True) # replace all blank values with 'NaN'
df.dropna(subset=['data'], inplace=True) #remove all the rows containing 'NaN' values
df.sort_values(by ='location', axis=0, ascending=True, inplace=True, kind='quicksort')
#sort based on location
df.reset_index(drop=True,inplace=True)
#reset index from random no. to 0,1,2,3... series
return df
class API_overview:
def overview_exe():
response = requests.get("https://www.trackcorona.live/api/countries")
a = response.json()['data']
df = json_normalize(a)
df.sort_values(by ='confirmed', axis=0, ascending=False, inplace=True, kind='quicksort', na_position='last')
df.reset_index(drop=True,inplace=True)
return df
def overview_bar(c,d,r):
y=[c,d,r]
label=['Confirmed','Dead','Recovered']
plt.bar([0,1,2],y,color=['yellow','red','green'])
plt.xticks([0,1,2],label,rotation=90)
plt.title('Overview of Covid19 Cases')
plt.show()
class CountryWise:
def CountryWise_exe():
df = API_overview.overview_exe()
df=df[['location','confirmed','dead','recovered']]
pd.set_option('display.max_rows', None)
print(df)
#graphs starts from here:-
#Confirmed
y=[i for i in df.confirmed[:30]]
x=[i for i in df.location[:30]]
plt.bar(x,y,color='yellow')
plt.xticks(x,x,rotation=90)
plt.title('Total Confirmed Cases Based on Countries')
plt.show()
#dead
y=[i for i in df.dead[:30]]
x=[i for i in df.location[:30]]
plt.bar(x,y,color='red')
plt.xticks(x,x,rotation=90)
plt.title('Total Death Cases Based on Countries')
plt.show()
#recovered
y=[i for i in df.recovered[:30]]
x=[i for i in df.location[:30]]
plt.bar(x,y,color='green')
plt.xticks(x,x,rotation=90)
plt.title('Total Recovered Cases Based on Countries')
plt.show()