Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2020
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.03 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. import urllib
  4. import pandas
  5. import json
  6. import matplotlib.pyplot as plt
  7.  
  8. response = urllib.request.urlopen('https://coronavirus-tracker-api.herokuapp.com/confirmed')
  9. #response = urllib.request.urlopen('https://coronavirus-tracker-api.herokuapp.com/deaths')
  10. d = json.loads(response.read())
  11.  
  12. #filename = 'confirmed.json'
  13. #with open(filename) as f:
  14. #    d = json.load(f)
  15.  
  16. item = {}
  17. countrylst = []
  18. newdata = pandas.DataFrame()
  19. for item in d['locations']:
  20.     country = item['country']
  21.     if item['province']:
  22.         country = country+'.'+item['province']
  23.     itemslst = list(map(lambda x: x[1], item["history"].items()))
  24.     if not newdata.empty:
  25.         itemslst = [ x for x in itemslst if x > 100 ]
  26.     if not itemslst:
  27.         continue
  28.     newdata[country] = pandas.Series(itemslst).pct_change(periods=1)
  29.     print(country)
  30.  
  31. newdata.plot(subplots=True, grid=True, x=newdata.index.name,
  32.         y=['China.Hubei', 'US', 'Germany', 'Turkey', 'Russia'])
  33. print(newdata.head(10))
  34. plt.savefig('data.png')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement