- url='https://od.cdc.gov.tw/eic/Age_County_Gender_19Cov.json'
- import requests
- data=requests.get(url)
pprint用法
- import pprint
- for item in jsonTxt:
- print(type(item))
- print(item)
- pprint.pprint(item)
-
已經無國籍欄位,要小修改
- N=0
- regions=['空值']
- rN=[0]
- NofR=1
- for item in jsonTxt:
- y=item['縣市']
- n=int(item['確定病例數'])
- if y not in regions:
- regions.append(y)
- NofR+=1
- rN.append(n)
- elif y=='空值':
- rN[0]+=n
- else:
- i=regions.index(y)
- rN[i]+=n
- N+=n
- print("{}...{}".format(y,n))
-
加上統計圖
- import matplotlib.pyplot as plt
- plt.rcParams['font.family']=['Microsoft JhengHei']
- plt.bar(regions, rN)
- plt.title('台灣縣市covid-19統計')
- plt.savefig('covid-19couty.png')
- plt.show()
沒有留言:
張貼留言