Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- import urllib
- import pandas
- import json
- import matplotlib.pyplot as plt
- response = urllib.request.urlopen('https://coronavirus-tracker-api.herokuapp.com/confirmed')
- #response = urllib.request.urlopen('https://coronavirus-tracker-api.herokuapp.com/deaths')
- d = json.loads(response.read())
- #filename = 'confirmed.json'
- #with open(filename) as f:
- # d = json.load(f)
- item = {}
- countrylst = []
- newdata = pandas.DataFrame()
- for item in d['locations']:
- country = item['country']
- if item['province']:
- country = country+'.'+item['province']
- itemslst = list(map(lambda x: x[1], item["history"].items()))
- if not newdata.empty:
- itemslst = [ x for x in itemslst if x > 100 ]
- if not itemslst:
- continue
- newdata[country] = pandas.Series(itemslst).pct_change(periods=1)
- print(country)
- newdata.plot(subplots=True, grid=True, x=newdata.index.name,
- y=['China.Hubei', 'US', 'Germany', 'Turkey', 'Russia'])
- print(newdata.head(10))
- plt.savefig('data.png')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement