資源簡(jiǎn)介
2019_nCoV.zip
代碼片段和文件信息
#!/usr/bin/env?python
#?coding:?utf-8
#?+?數(shù)據(jù)源?[騰訊疫情實(shí)時(shí)追蹤](https://news.qq.com/zt2020/page/feiyan.htm?from=timeline&isappinstalled=0)
#?###?第一部分?網(wǎng)頁(yè)分析
#?###?第二部分?數(shù)據(jù)準(zhǔn)備
#?####?導(dǎo)入模塊
import?time?
import?json
import?requests
from?datetime?import?datetime
import?pandas?as?pd?
import?numpy?as?np?
#?####?抓取數(shù)據(jù)
def?catch_data():
????url?=?‘https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5‘
????reponse?=?requests.get(url=url).json()
????#返回?cái)?shù)據(jù)字典
????data?=?json.loads(reponse[‘data‘])
????return?data
data?=?catch_data()
data.keys()
#?####?數(shù)據(jù)處理
#?數(shù)據(jù)集包括[“國(guó)內(nèi)總量““國(guó)內(nèi)新增““更新時(shí)間““數(shù)據(jù)明細(xì)““每日數(shù)據(jù)““每日新增“]
lastUpdateTime?=?data[‘lastUpdateTime‘]
chinaTotal?=?data[‘chinaTotal‘]
chinaAdd?=?data[‘chinaAdd‘]
print(chinaTotal)
print(chinaAdd)
#?#####?國(guó)內(nèi)數(shù)據(jù)處理?第一步
#?數(shù)據(jù)明細(xì),數(shù)據(jù)結(jié)構(gòu)比較復(fù)雜,一步一步打印出來(lái)看,先明白數(shù)據(jù)結(jié)構(gòu)
areaTree?=?data[‘a(chǎn)reaTree‘]
#?國(guó)內(nèi)數(shù)據(jù)
china_data?=?areaTree[0][‘children‘]
china_list?=?[]
for?a?in?range(len(china_data)):
????province?=?china_data[a][‘name‘]
????province_list?=?china_data[a][‘children‘]
????for?b?in?range(len(province_list)):
????????city?=?province_list[b][‘name‘]
????????total?=?province_list[b][‘total‘]
????????today?=?province_list[b][‘today‘]
????????china_dict?=?{}
????????china_dict[‘province‘]?=?province
????????china_dict[‘city‘]?=?city
????????china_dict[‘total‘]?=?total
????????china_dict[‘today‘]?=?today
????????china_list.append(china_dict)
????????
china_data?=?pd.Dataframe(china_list)
china_data.head()
#?#####?國(guó)內(nèi)數(shù)據(jù)處理?第二步
#?定義數(shù)據(jù)處理函數(shù)
def?confirm(x):
????confirm?=?eval(str(x))[‘confirm‘]
????return?confirm
def?suspect(x):
????suspect?=?eval(str(x))[‘suspect‘]
????return?suspect
def?dead(x):
????dead?=?eval(str(x))[‘dead‘]
????return?dead
def?heal(x):
????heal?=??eval(str(x))[‘heal‘]
????return?heal
#?函數(shù)映射
china_data[‘confirm‘]?=?china_data[‘total‘].map(confirm)
china_data[‘suspect‘]?=?china_data[‘total‘].map(suspect)
china_data[‘dead‘]?=?china_data[‘total‘].map(dead)
china_data[‘heal‘]?=?china_data[‘total‘].map(heal)
china_data[‘a(chǎn)ddconfirm‘]?=?china_data[‘today‘].map(confirm)
china_data[‘a(chǎn)ddsuspect‘]?=?china_data[‘today‘].map(suspect)
china_data[‘a(chǎn)dddead‘]?=?china_data[‘today‘].map(dead)
china_data[‘a(chǎn)ddheal‘]?=?china_data[‘today‘].map(heal)
china_data?=?china_data[[“province““city““confirm““suspect““dead““heal““addconfirm““addsuspect““adddead““addheal“]]
china_data.head()
#?#####?國(guó)際數(shù)據(jù)處理
global_data?=?pd.Dataframe(data[‘a(chǎn)reaTree‘])
global_data[‘confirm‘]?=?global_data[‘total‘].map(confirm)
global_data[‘suspect‘]?=?global_data[‘total‘].map(suspect)
global_data[‘dead‘]?=?global_data[‘total‘].map(dead)
global_data[‘heal‘]?=?global_data[‘total‘].map(heal)
global_data[‘a(chǎn)ddconfirm‘]?=?global_data[‘today‘].map(confirm)
global_data[‘a(chǎn)ddsuspect‘]?=?global_data[‘today‘].map(suspect)
global_data[‘a(chǎn)dddead‘]?=?global_data[‘today‘].map(dead)
global_data[‘a(chǎn)ddheal‘]?=?global_data[‘today‘].map(heal)
world_name?=?pd.read_excel(“世界各國(guó)中英文對(duì)照.xlsx“)
global_data?=?pd.merge(global_dataworld_nameleft_on?=“name“right_on?=?“中文“how=“inner“)
global_d
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件???????40772??2020-02-03?12:04??2019_nCoV?可視化.html
?????文件??????397720??2020-02-03?11:56??2019_nCoV?可視化2.0.ipynb
?????文件????????8124??2020-02-03?12:03??2019_nCoV?可視化2.0.py
?????文件???????55874??2020-02-03?11:46??2019_nCoV.ipynb
?????文件???????98890??2020-01-30?14:17??2019_nCoV_預(yù)測(cè)(無(wú)實(shí)際意義).ipynb
?????文件????????6325??2020-02-02?18:21??daily_data.xlsx
?????文件???????16095??2020-01-29?17:34??世界各國(guó)中英文對(duì)照.xlsx
評(píng)論
共有 條評(píng)論