欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python疫情數(shù)據(jù)可視化分析

 更新時(shí)間:2022年07月11日 17:14:19   作者:謝謝大家我愛(ài)小謝  
這篇文章主要介紹了Python疫情數(shù)據(jù)可視化分析,本數(shù)據(jù)集主要涉及到全球疫情統(tǒng)計(jì),包括確診、治愈、死亡、時(shí)間、國(guó)家、地區(qū)等信息,需要的朋友可以參考一下

前言

本項(xiàng)目主要通過(guò)python的matplotlib pandas pyecharts等庫(kù)對(duì)疫情數(shù)據(jù)進(jìn)行可視化分析

數(shù)據(jù)來(lái)源:

  • 本數(shù)據(jù)集來(lái)源于kaggle競(jìng)賽的開(kāi)源數(shù)據(jù)集,數(shù)據(jù)集地址
  • 本數(shù)據(jù)集主要涉及到全球疫情統(tǒng)計(jì),包括確診、治愈、死亡、時(shí)間、國(guó)家、地區(qū)等信息

功能函數(shù)

讀取文件

df = pd.read_csv(r'C:\Users\Hasee\Desktop/covid_19_data.csv')
df.head()

更換列名,便于查看

cols= ['序號(hào)','日期','省/州','國(guó)家','最近更新','確診','死亡','治愈']
df.columns = cols
df.日期 = pd.to_datetime(df.日期)
df

## 利用groupby按照日期統(tǒng)計(jì)確診死亡治愈病例的總和

#合并同一天同國(guó)家日期
global_confirm = df.groupby('日期')[['確診', '死亡', '治愈']].sum()
global_confirm

全球疫情趨勢(shì)

ax = global_confirm.plot(figsize = (12,10), title = '全球疫情趨勢(shì)圖')

篩選出中國(guó)的數(shù)據(jù)

利用groupby按照日期統(tǒng)計(jì)確診死亡治愈病例的總和

global_china = df[df['國(guó)家'] == 'Mainland China'].reset_index()
global_china_confirm  =  global_china.groupby('日期')[['確診', '死亡', '治愈']].sum().reset_index()

畫(huà)圖,三條線組合到一個(gè)圖

利用groupby按照省統(tǒng)計(jì)確診死亡治愈病例的總和

global_china = df[df['國(guó)家'] == '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)

確診人數(shù)排名前15的國(guó)家

plt.figure(figsize=(16,16))
plt.barh(list(global_country_confirm_rank.國(guó)家)[::-1], list(global_country_confirm_rank.確診)[::-1])
plt.title('確診人數(shù)排名前15的國(guó)家')
plt.xlabel('人數(shù)(千萬(wàn))')
plt.ylabel('國(guó)家')

這里用pyecharts庫(kù)畫(huà)圖,繪制的玫瑰圖,rosetype

set_global_opts是設(shè)置格式:

中國(guó)確診人數(shù)前十的省

china_confirm = df[df['國(guó)家'] == "Mainland China"]
china_latest = china_confirm[china_confirm['日期'] == max(china_confirm['日期'])]

words = WordCloud()
words.add('確診人數(shù)', [tuple(dic) for dic in zip(list(china_latest['省/州']),list(china_latest['確診']))], word_size_range=[20,100])

區(qū)域圖

china_death = df[df['國(guó)家'] == "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("中國(guó)死亡病例分布", [list(z) for z in zip(china_death_prodic,list(china_death_latest['死亡']))], "china")
geo.set_global_opts(title_opts=opts.TitleOpts(title="全國(guó)各省死亡病例數(shù)據(jù)分布"),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 = Geo()
geo.add_schema(maptype="china")

geo.add("中國(guó)死亡病例分布", [list(dic) for dic in zip(china_death_prodic,list(china_death_latest['死亡']))],type_=GeoType.EFFECT_SCATTER)
geo.set_global_opts(visualmap_opts=opts.VisualMapOpts(),title_opts=opts.TitleOpts(title="全國(guó)各省死亡病例數(shù)據(jù)分布"))
geo.render_notebook()

全球死亡人數(shù)地理分布情況

map = Map()
map.set_global_opts(title_opts=opts.TitleOpts(title="全球死亡人數(shù)地理分布情況"),visualmap_opts=opts.VisualMapOpts(is_piecewise=True,
                    pieces=[
                    {"min": 100001, "label": '>100001人', "color": "#6F171F"}, 
                    {"min": 10001, "max": 100000, "label": '10001-100000人', "color": "#C92C34"},
                    {"min": 1001, "max": 10000, "label": '1001-10000人', "color": "#E35B52"},
                    {"min": 101, "max": 10000, "label": '101-10000人', "color": "#F39E86"},
                    {"min": 1, "max": 100, "label": '1-100人', "color": "#FDEBD0"}]))
map.add("全球死亡人數(shù)地理分布情況", [list(z) for z in zip(global_death_n,list(global_death['死亡']))], "world")
map.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
map.render_notebook()

全球疫情頻率直方圖

global_confirm.plot.hist(alpha=0.5)
plt.xlabel('人數(shù)(千萬(wàn))')
plt.ylabel('出現(xiàn)頻率')
plt.title('全球疫情頻率直方圖')

其他圖

陜西確診病例餅圖

陜西省確診病例數(shù)據(jù)分布

中國(guó)治愈病例玫瑰圖

到此這篇關(guān)于Python疫情數(shù)據(jù)可視化分析的文章就介紹到這了,更多相關(guān)Python可視化內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論