全球疫情数据分析
我是本际云服务器推荐网的小编小本本,今天想从数据分析的角度对全球疫情情况进行一个分析,包括确诊、治愈、死亡、时间、国家、地区等这些数据,并进行相关的可视化数据分析。

数据处理和可视化分析
本项目主要利用python的matplotlib、pandas、pyecharts等库对疫情数据进行可视化分析。数据集来源于kaggle竞赛的开源数据集,主要涉及到全球疫情统计,包括确诊、治愈、死亡、时间、国家、地区等信息。接下来,我们就一步步对数据进行处理和可视化分析。
具体实现过程
首先,我们需要读取数据集文件:
df=pd.read_csv(r'C:\Users\Hasee\Desktop/covid_19_data.csv')
然后,我们更换列名方便查看:
cols=['序号','日期','省/州','国家','最近更新','确诊','死亡','治愈']
df.columns=cols
df.日期=pd.to_datetime(df.日期)
df
接着,我们利用groupby按照日期统计确诊、死亡、治愈病例的总和,并绘制全球疫情趋势图:
global_confirm=df.groupby('日期')[['确诊','死亡','治愈']].sum()
global_confirm
ax=global_confirm.plot(figsize=(12,10),title='全球疫情趋势图')
然后,我们筛选出中国的数据,并按照日期统计确诊、死亡、治愈病例的总和,绘制出三条线的趋势图:
global_china=df[df['国家']=='Mainland China'].reset_index()
global_china_confirm=global_china.groupby('日期')[['确诊','死亡','治愈']].sum().reset_index()
接着,我们按照省/州统计确诊、死亡、治愈病例的总和,并利用100%玫瑰图呈现出中国治愈情况的比例分布:
global_china=df[df['国家']=='Mainland China'].reset_index()
global_china_province_confirm=global_china.groupby('省/州')[['确诊','死亡','治愈']].sum().reset_index()
recovercent=100.*global_china_province_confirm['治愈']/global_china_province_confirm['治愈'].sum()
labels=['{0}-{1:1.2f}%-{2}'.format(i,j,k)for i,j,k in zip(list(global_china_province_confirm['省/州']),recovercent,list(global_china_province_confirm['治愈']))]
plt.figure(figsize=(10,10))
plt.pie(global_china_province_confirm['治愈'],radius=0.3)
然后,我们绘制出确诊人数排名前15的国家条形图:
plt.figure(figsize=(16,16))
plt.barh(list(global_country_confirm_rank.国家)[::-1],list(global_country_confirm_rank.确诊)[::-1])
plt.title('确诊人数排名前15的国家')
plt.xlabel('人数(千万)')
plt.ylabel('国家')
接着,我们利用pyecharts库画出中国确诊人数前十的省份区域图:
china_confirm=df[df['国家']=="Mainland China"]
china_latest=china_confirm[china_confirm['日期']==max(china_confirm['日期'])]
words=WordCloud()
words.add('确诊人数',[tuple(dic)for dic in zip(list(china_latest['省/州']),list(china_latest['确诊']))],word_size_range=[20,100])
然后,我们利用Geo库画出全国各省死亡病例数据分布的地图:
china_death=df[df['国家']=="Mainland China"]
china_death_latest=china_death[china_death['日期']==max(china_death['日期'])]
china_death_latest=china_death_latest.groupby('省/州')[['确诊','死亡']].max().reset_index()
geo=Map()
geo.add("中国死亡病例分布",[list(z)for z in zip(china_death_prodic,list(china_death_latest['死亡']))],"china")
geo.set_global_opts(title_opts=opts.TitleOpts(title="全国各省死亡病例数据分布"),visualmap_opts=opts.VisualMapOpts(is_piecewise=True,
pieces=[
{"min":1500,"label":'>10000人',"color":"#6F171F"},
{"min":500,"max":15000,"label":'500-1000人',"color":"#C92C34"},
{"min":100,"max":499,"label":'100-499人',"color":"#E35B52"},
{"min":10,"max":99,"label":'10-99人',"color":"#F39E86"},
{"min":1,"max":9,"label":'1-9人',"color":"#FDEBD0"}]))
geo.render_notebook()
接着,我们利用Geo库画出全球死亡人数地理分布情况的地图:
map=Map()
map.set_global
原创文章,作者:小编小本本,如若转载,请注明出处:https://www.benjiyun.com/yunzhujiyunwei/vps-yunwei/7419.html
