程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python collects epidemic data and makes visual display

編輯:Python

Preface

Good morning, everyone 、 Good afternoon 、 Good evening ~

Catalog ( You can click on the place you want to see )

  • Preface
      • This code is provided by : Qingdeng Education - Teacher Siyue
  • Knowledge point
  • development environment
  • Code
    • Collect data
      • The import module
      • Send a request
      • get data
      • Parsing data
      • Save the data
      • effect
    • Data visualization
      • The import module
      • Reading data
      • Mortality and cure rate
      • Number of confirmed cases and deaths in various regions
  • Tail language


This code is provided by : Qingdeng Education - Teacher Siyue


Knowledge point

  • Basic flow of crawler
  • json
  • requests Among reptiles Send network request
  • pandas Form handling / Save the data
  • pyecharts visualization

development environment

  • python 3.8 Relatively stable version Interpreter distribution anaconda jupyter notebook Write data analysis code inside speciality
  • pycharm Professional code editor Version by year and month

Code

Collect data

The import module

import requests # Send network request module
import json
import pprint # Format output module
import pandas as pd # Data analysis is a very important module

Target data to crawl today

https://news.qq.com/zt2020/page/feiyan.htm#/

Send a request

url = 'https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5&_=1638361138568'
response = requests.get(url, verify=False)

get data

json_data = response.json()['data']

Parsing data

json_data = json.loads(json_data)
china_data = json_data['areaTree'][0]['children'] # list
data_set = []
for i in china_data:
data_dict = {
}
# Area name
Source code 、 answer 、 course 、 Can dress if necessary :832157862
data_dict['province'] = i['name']
# Add confirmation
data_dict['nowConfirm'] = i['total']['nowConfirm']
# The number of deaths
data_dict['dead'] = i['total']['dead']
# The number of people cured
data_dict['heal'] = i['total']['heal']
# mortality
data_dict['deadRate'] = i['total']['deadRate']
# Cure rate
data_dict['healRate'] = i['total']['healRate']
data_set.append(data_dict)

Save the data

df = pd.DataFrame(data_set)
df.to_csv('data.csv')

effect

Data visualization

The import module

from pyecharts import options as opts
Source code 、 answer 、 course 、 Can dress if necessary :832157862
from pyecharts.charts import Bar,Line,Pie,Map,Grid

Reading data

df2 = df.sort_values(by=['nowConfirm'],ascending=False)[:9]
df2

Mortality and cure rate

line = (
Line()
.add_xaxis(list(df['province'].values))
.add_yaxis(" Cure rate ", df['healRate'].values.tolist())
.add_yaxis(" mortality ", df['deadRate'].values.tolist())
.set_global_opts(
title_opts=opts.TitleOpts(title=" Mortality and cure rate "),
)
)
line.render_notebook()

Number of confirmed cases and deaths in various regions

bar = (
Bar()
.add_xaxis(list(df['province'].values)[:6])
.add_yaxis(" Death ", df['dead'].values.tolist()[:6])
.add_yaxis(" Cure ", df['heal'].values.tolist()[:6])
.set_global_opts(
Source code 、 answer 、 You can dress up if necessary :832157862
title_opts=opts.TitleOpts(title=" Number of confirmed cases and deaths in various regions "),
datazoom_opts=[opts.DataZoomOpts()],
)
)
bar.render_notebook()

Tail language

Okay , My article ends here !

There are more suggestions or questions to comment on or send me a private letter ! Come on together and work hard (ง •_•)ง

If you like, just pay attention to the blogger , Or like the collection and comment on my article !!!


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved