日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

Python爬虫爬取疫情数据并可视化展示

發(fā)布時間:2023/12/31 python 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python爬虫爬取疫情数据并可视化展示 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

?這篇文章主要介紹了Python利用爬蟲爬取疫情數(shù)據(jù)并進行可視化的展示,文中的示例代碼講解清晰,對工作或?qū)W習有一定的價值,需要的朋友可以參考一下。編程資料點擊領取

目錄

知識點

開發(fā)環(huán)境

爬蟲完整代碼

導入模塊

分析網(wǎng)站

發(fā)送請求

獲取數(shù)據(jù)

解析數(shù)據(jù)

保存數(shù)據(jù)

數(shù)據(jù)可視化

導入模塊

讀取數(shù)據(jù)

死亡率與治愈率

各地區(qū)確診人數(shù)與死亡人數(shù)情況


知識點

  • 爬蟲基本流程
  • json
  • requests 爬蟲當中 發(fā)送網(wǎng)絡請求
  • pandas 表格處理 / 保存數(shù)據(jù)
  • pyecharts 可視化
  • 開發(fā)環(huán)境

    python 3.8 比較穩(wěn)定版本 解釋器發(fā)行版 anaconda jupyter notebook 里面寫數(shù)據(jù)分析代碼 專業(yè)性

    pycharm 專業(yè)代碼編輯器 按照年份與月份劃分版本的

    爬蟲完整代碼

    導入模塊

    1

    2

    3

    4

    import requests????? # 發(fā)送網(wǎng)絡請求模塊

    import json

    import pprint??????? # 格式化輸出模塊

    import pandas as pd? # 數(shù)據(jù)分析當中一個非常重要的模塊

    分析網(wǎng)站

    先找到今天要爬取的目標數(shù)據(jù)

    實時更新:新冠肺炎疫情最新動態(tài)

    找到數(shù)據(jù)所在url

    發(fā)送請求

    1

    2

    url = 'https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5&_=1638361138568'

    response = requests.get(url, verify=False)

    獲取數(shù)據(jù)

    1

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

    解析數(shù)據(jù)

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    json_data = json.loads(json_data)

    china_data = json_data['areaTree'][0]['children'] # 列表

    data_set = []

    for i in china_data:

    ????data_dict = {}

    ????# 地區(qū)名稱

    ????data_dict['province'] = i['name']

    ????# 新增確認

    ????data_dict['nowConfirm'] = i['total']['nowConfirm']

    ????# 死亡人數(shù)

    ????data_dict['dead'] = i['total']['dead']

    ????# 治愈人數(shù)

    ????data_dict['heal'] = i['total']['heal']

    ????# 死亡率

    ????data_dict['deadRate'] = i['total']['deadRate']

    ????# 治愈率

    ????data_dict['healRate'] = i['total']['healRate']

    ????data_set.append(data_dict)

    保存數(shù)據(jù)

    1

    2

    df = pd.DataFrame(data_set)

    df.to_csv('data.csv')

    數(shù)據(jù)可視化

    導入模塊

    1

    2

    from pyecharts import options as opts

    from pyecharts.charts import Bar,Line,Pie,Map,Grid

    讀取數(shù)據(jù)

    1

    2

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

    df2

    死亡率與治愈率

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    line = (

    ????Line()

    ????.add_xaxis(list(df['province'].values))

    ????.add_yaxis("治愈率", df['healRate'].values.tolist())

    ????.add_yaxis("死亡率", df['deadRate'].values.tolist())

    ????.set_global_opts(

    ????????title_opts=opts.TitleOpts(title="死亡率與治愈率"),

    ????)

    )

    line.render_notebook()

    各地區(qū)確診人數(shù)與死亡人數(shù)情況

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    bar = (

    ????Bar()

    ????.add_xaxis(list(df['province'].values)[:6])

    ????.add_yaxis("死亡", df['dead'].values.tolist()[:6])

    ????.add_yaxis("治愈", df['heal'].values.tolist()[:6])

    ????.set_global_opts(

    ????????title_opts=opts.TitleOpts(title="各地區(qū)確診人數(shù)與死亡人數(shù)情況"),

    ????????datazoom_opts=[opts.DataZoomOpts()],

    ????????)

    )

    bar.render_notebook()

    以上就是Python爬蟲爬取疫情數(shù)據(jù)并可視化展示的詳細內(nèi)容。

    感謝關(guān)注,為你們準備了編程學習的一套資料,還有相應的代碼,視頻教程都可以獲取,添加Q裙703046414即可獲取。

    總結(jié)

    以上是生活随笔為你收集整理的Python爬虫爬取疫情数据并可视化展示的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。