parent
85c32ed261
commit
92c867673e
@ -0,0 +1,146 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "035bbe94",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"url = 'https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5&_=1638361138568'\n",
|
||||
"response = requests.get(url, verify=False) "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "7958e476",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"json_data = response.json()['data'] "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "aedf9134",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"json_data = json.loads(json_data)\n",
|
||||
"china_data = json_data['areaTree'][0]['children'] # 列表\n",
|
||||
"data_set = []\n",
|
||||
"for i in china_data:\n",
|
||||
" data_dict = {}\n",
|
||||
" # 地区名称\n",
|
||||
" data_dict['province'] = i['name']\n",
|
||||
" # 新增确认\n",
|
||||
" data_dict['nowConfirm'] = i['total']['nowConfirm']\n",
|
||||
" # 死亡人数\n",
|
||||
" data_dict['dead'] = i['total']['dead']\n",
|
||||
" # 治愈人数\n",
|
||||
" data_dict['heal'] = i['total']['heal']\n",
|
||||
" # 死亡率\n",
|
||||
" data_dict['deadRate'] = i['total']['deadRate']\n",
|
||||
" # 治愈率\n",
|
||||
" data_dict['healRate'] = i['total']['healRate']\n",
|
||||
" data_set.append(data_dict) "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "003fe7e4",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"df = pd.DataFrame(data_set)\n",
|
||||
"df.to_csv('data.csv')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "898540cc",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from pyecharts import options as opts\n",
|
||||
"from pyecharts.charts import Bar,Line,Pie,Map,Grid "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "02fa2050",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"df2 = df.sort_values(by=['nowConfirm'],ascending=False)[:9]\n",
|
||||
"df2"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "1801a511",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"line = (\n",
|
||||
" Line()\n",
|
||||
" .add_xaxis(list(df['province'].values))\n",
|
||||
" .add_yaxis(\"治愈率\", df['healRate'].values.tolist())\n",
|
||||
" .add_yaxis(\"死亡率\", df['deadRate'].values.tolist())\n",
|
||||
" .set_global_opts(\n",
|
||||
" title_opts=opts.TitleOpts(title=\"死亡率与治愈率\"),\n",
|
||||
"\n",
|
||||
" )\n",
|
||||
")\n",
|
||||
"line.render_notebook() "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "b9895713",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"bar = (\n",
|
||||
" Bar()\n",
|
||||
" .add_xaxis(list(df['province'].values)[:6])\n",
|
||||
" .add_yaxis(\"死亡\", df['dead'].values.tolist()[:6])\n",
|
||||
" .add_yaxis(\"治愈\", df['heal'].values.tolist()[:6])\n",
|
||||
" .set_global_opts(\n",
|
||||
" title_opts=opts.TitleOpts(title=\"各地区确诊人数与死亡人数情况\"),\n",
|
||||
" datazoom_opts=[opts.DataZoomOpts()],\n",
|
||||
" )\n",
|
||||
")\n",
|
||||
"bar.render_notebook() "
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.9.7"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
Loading…
Reference in new issue