Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3648342
  • 博文数量: 365
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 2522
  • 用 户 组: 普通用户
  • 注册时间: 2019-10-28 13:40
文章分类

全部博文(365)

文章存档

2023年(8)

2022年(130)

2021年(155)

2020年(50)

2019年(22)

我的朋友

分类: Python/Ruby

2022-06-01 17:13:50

import requests      # 发送网络请求模块

import json

import pprint        # 格式化输出模块

import pandas as pd  # 数据分析当中一个非常重要的模块

from pyecharts import options as opts

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

from pyecharts.globals import CurrentConfig, NotebookType

# 配置对应的环境类型

CurrentConfig.NOTEBOOK_TYPE = NotebookType.JUPYTER_NOTEBOOK

CurrentConfig.ONLINE_HOST=''

url = ''

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

json_data =跟单网gendan5.com response.json()['data']

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

data_set = []

for i in china_data:

    data_dict = {}

    # 地区名称

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

    # 新增确认

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

    # 死亡人数

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

    # 治愈人数

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

    data_set.append(data_dict)

df = pd.DataFrame(data_set)

df.to_csv('yiqing_data.csv')

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

df2

# 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="各地区确诊人数与死亡人数情况"),

#         datazoom_opts=[opts.DataZoomOpts()],

#         )

# )

# bar.render_notebook()

# china_map = (

#     Map()

#     .add("现有确诊", [list(i) for i in zip(df['province'].values.tolist(),df['nowConfirm'].values.tolist())], "china")

#     .set_global_opts(

#         title_opts=opts.TitleOpts(title="各地区确诊人数"),

#         visualmap_opts=opts.VisualMapOpts(max_=600, is_piecewise=True),

#     )

# )

# china_map.render_notebook()

# pie = (

#     Pie()

#     .add(

#         "",

#         [list(i) for i in zip(df2['province'].values.tolist(),df2['nowConfirm'].values.tolist())],

#         radius = ["10%","30%"]

#     )

#     .set_global_opts(

#             legend_opts=opts.LegendOpts(orient="vertical", pos_top="70%", pos_left="70%"),

#     )

#     .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}"))

# )

# pie.render_notebook()

line = (

    Line()

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

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

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

    .set_global_opts(

        title_opts=opts.TitleOpts(title="死亡与治愈"),

    )

)

line.render_notebook()

阅读(1427) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~