0
本文作者: skura | 2020-02-18 11:35 |
CDC 發(fā)布在 Unsplash 上的照片
一種最初在中國城市武漢被發(fā)現(xiàn)的病毒,現(xiàn)在已經(jīng)傳播到世界上十幾個國家,引發(fā)了前所未有的健康和經(jīng)濟危機。
世界衛(wèi)生組織(簡稱世衛(wèi)組織)宣布武漢冠狀病毒爆發(fā)為「國際關(guān)注的公共衛(wèi)生突發(fā)事件」。
在本文中,我們將簡要回顧當前的危機,然后深入研究 Kaggle 的「Novel Corona Virus 2019 Dataset」。我創(chuàng)建了一個 GitHub repo,以供大家發(fā)表自己的見解。
什么是冠狀病毒?
據(jù)世衛(wèi)組織稱,冠狀病毒(CoV)是一個病毒大家族,它們引起的疾病很多,包括普通感冒和更嚴重的疾病,如中東呼吸綜合征(MERS-CoV)和嚴重急性呼吸綜合征(SARS-CoV)。
新型冠狀病毒(nCoV)是一種新的病毒株,此前尚未被人類發(fā)現(xiàn)。最近爆發(fā)的病毒被稱為 2019-nCoV 或武漢冠狀病毒。
我們面臨的危機
此前,據(jù)《紐約時報》的一篇報道,「確診感染人數(shù)上升至 37198 人」,「中國死亡人數(shù)上升至811人,超過了非典疫情造成的死亡人數(shù)」。
中國有 16 個城市,超過 5000 萬人口,正處于封鎖狀態(tài)。全球各地的航空公司都取消了往返中國的航班。一些國家正通過特別航班疏散本國公民,并進一步對他們實施嚴格的隔離。
更糟糕的是,中國股市暴跌,全球股市受到了影響。一些分析人士預測,疫情對全球經(jīng)濟構(gòu)成的威脅,有可能引發(fā)深遠的政治后果。
數(shù)據(jù)集簡介
約翰霍普金斯大學收集了「Novel Corona Virus 2019 Dataset」,并將該數(shù)據(jù)集發(fā)表在 Kaggle 上。該小組從世界衛(wèi)生組織、當?shù)丶部刂行暮兔襟w等不同渠道收集了這些數(shù)據(jù)。他們還創(chuàng)建了一個實時儀表盤來監(jiān)控病毒的傳播
免責聲明:請注意,數(shù)據(jù)集沒有更新,因此下面記錄的結(jié)果可能不是當前現(xiàn)狀的真實反映。
導入庫并加載數(shù)據(jù)
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
#reading data from the csv file
data= pd.read_csv("/kaggle/input/novel-corona-virus-2019-dataset/2019_nCoV_data.csv")
理解數(shù)據(jù)集
讓我們首先對數(shù)據(jù)集有一個基本的了解,并在必要時執(zhí)行數(shù)據(jù)清洗操作。
#checking the number of rows and columns
data.shape
輸出:(770,8)。數(shù)據(jù)集中有 8 列共 770 個觀測值。
#checking the top 5 rows
data.head()
列的名稱顯而易見。第一列「Sno」看起來像行號,不向分析添加任何值。第五列「Last Update」顯示的值與「Date」列相同,但少數(shù)情況下,這些數(shù)字稍后會更新。在繼續(xù)之前,我們先刪除這兩列。
#dropping the 1st and 5th column
data.drop("Sno", axis=1, inplace=True)
data.drop("Last Update", axis=1, inplace=True)
#getting a summary of the columns
data.info()
除「Province/State」外,所有列都沒有空值。進一步分析顯示,英國、法國和印度等國的省份名稱都不見了。在這種情況下,我們不能假設或填充任何主列表中缺少的值。讓我們轉(zhuǎn)到數(shù)字列。
data.describe()
describe() 方法返回數(shù)據(jù)幀中數(shù)值列的一般統(tǒng)計信息。
這個輸出可以得到的一個直接結(jié)論是,數(shù)據(jù)已經(jīng)累積報告,即任何一天報告的病例數(shù)包括先前報告的病例。死亡的最大值是 479,這與幾天前媒體的報道(在這一數(shù)據(jù)公布時)是一致的。
#checking for duplicate rows
duplicate_rows=data.duplicated(['Country','Province/State','Date'])
data[duplicate_rows]
duplicated() 方法返回一個布爾序列,然后將其用作原始數(shù)據(jù)幀的掩碼。結(jié)果顯示沒有兩個記錄具有相同的國家、州和日期。因此我們可以得出結(jié)論,數(shù)據(jù)集中的所有觀測值都是唯一的。
#listing all the countries where the virus has spread to
country_list=list(data['Country'].unique())
print(country_list)
print(len(country_list))
數(shù)據(jù)顯示,該病毒已經(jīng)傳播到亞洲、歐洲和美洲的 32 個國家。為了進行分析,我們可以合并「China」和「Mainland China」的數(shù)據(jù)。
#merging China and Mainland China
data.loc[data['Country']=='Mainland China','Country']='China'
在開始之前,讓我們檢查一下 [Date] 欄中的日期。
print(list(data['Date'].unique()))
print(len(list(data['Date'].unique())))
數(shù)據(jù)似乎每天都在不同的時間更新。我們可以從時間戳中提取日期并將其用于進一步的分析。這將有助于我們保持日期一致。
#converting 'Date' column to datetime object
data['Date'] = pd.to_datetime(data['Date'])
#extracting dates from timestamps
data['Date_date']=data['Date'].apply(lambda x:x.date())
讓我們了解一下疫情對每個國家的影響。
#getting the total number of confirmed cases for each country
df_country=data.groupby(['Country']).max().reset_index(drop=None)
print(df_country[['Country','Confirmed','Deaths','Recovered']])
由于數(shù)據(jù)是累積的,所以我們需要使用 groupby() 和 max() 函數(shù),以獲得每個國家報告的最大數(shù)目。如果我們使用 sum(),則會導致重復計算。
數(shù)據(jù)證實,迄今為止,中國報告的病例最多,481 例死亡病例幾乎全部來自中國。但另一方面,中國也有 522 人康復,其次是泰國,有 7 人康復。
#preparing data for a time-series analysis
df_by_date=data.groupby(['Date_date']).sum().reset_index(drop=None)
df_by_date['daily_cases']=df_by_date.Confirmed.diff()
df_by_date['daily_deaths']=df_by_date.Deaths.diff()
df_by_date['daily_recoveries']=df_by_date.Recovered.diff()
print(df_by_date)
我們已經(jīng)完成了數(shù)據(jù)預處理步驟,接下來讓我們繼續(xù)進行數(shù)據(jù)可視化,以尋找新的趨勢和模式。
數(shù)據(jù)可視化
對于數(shù)據(jù)可視化,我們將使用兩個強大的 Python 庫:Matplotlib 和 Seaborn。Matplotlib 是大多數(shù)數(shù)據(jù)科學家使用的默認二維可視化庫。Seaborn 建立在 matplotlib 之上,有助于構(gòu)建更好看、更復雜的可視化效果,如熱圖就是用這個庫繪制的。
讓我們根據(jù)從數(shù)據(jù)的不同方面創(chuàng)建五個可視化圖。
1.一段時間內(nèi)的確診病例數(shù)
#plotting a bar chart of confirmed cases over time
sns.axes_style("whitegrid")
sns.barplot(
x="Date_date",
y="Confirmed",data=data.groupby(['Date_date']).sum().reset_index(drop=None)
)
plt.xticks(rotation=60)
plt.ylabel('Number of confirmed cases',fontsize=15)
plt.xlabel('Dates',fontsize=15)
2.死亡率與康復率
#plotting two line plots for deaths and recoveries respectively
plt.plot('date_updated', 'Deaths',
data=data.groupby(['date_updated']).sum().reset_index(drop=None), color='red')
plt.plot('date_updated', 'Recovered',
data=data.groupby(['date_updated']).sum().reset_index(drop=None), color='green')
plt.xticks(rotation=60)
plt.ylabel('Number of cases',fontsize=15)
plt.xlabel('Dates',fontsize=15)
plt.legend()
plt.show()
3.除中國外,受影響最嚴重的 10 個國家
#We know that China is the most affected country by a large margin,
#so lets create a bar plot to compare countries other than China
#increasing the figure size
plt.rcParams['figure.figsize']=(15,7)
sns.barplot(
x="Country",
y="Confirmed",
data=df_country[df_country.Country!='China'].nlargest(10,'Confirmed'),
palette=sns.cubehelix_palette(15, reverse=True)
)
plt.ylabel('Number of cases',fontsize=15)
plt.xlabel('Countries',fontsize=15)
plt.xticks(fontsize=13)
plt.yticks(fontsize=13)
4.死亡率和時間的關(guān)系
#The mortality rate, at any point in time, can be roughly calculated
#by dividing the number of deaths by the number of confirmed cases
df_by_date['mrate']=df_by_date.apply(lambda x: x['Deaths']*100/(x['Confirmed']), axis=1)
plt.plot('Date_date','mrate',data=df_by_date, color='red')
plt.show()
5.中國十大受災最重的省份
#creating a separate dataframe for provinces
df_province=data[data['Country']=='China'].groupby(['Province/State']).max().reset_index(drop=None)
#selecting 10 most affected provinces
df_province=df_province.nlargest(10,'Confirmed')
df_province=df_province[['Province/State','Deaths','Recovered']]
#for multi-bar plots in seaborn, we need to melt the dataframe so
#that the the deaths and recovered values are in the same column
df_province= df_province.melt(id_vars=['Province/State'])
sns.barplot(
x='Province/State',
y='value',
hue='variable',
data=df_province
)
plt.xlabel('Provinces',fontsize=15)
plt.ylabel('Number of cases',fontsize=15)
可視化結(jié)果分析
自 1 月 28 日以來,每天報告的病例數(shù)量增加了近250%。2 月 4 日報告的病例數(shù)為 3915 例。這表明該病毒具有高度的傳染性,正在迅速傳播。
在第一周,死亡率高于康復率。自 1 月 31 日以來,康復率迅速上升,并呈現(xiàn)出積極的趨勢。2 月 4 日有 255 人康復,而死亡人數(shù)為 66 人。隨著越來越多的人了解癥狀并及時尋求藥物治療,康復率將繼續(xù)提高。
與在地理上和中國位置相近的國家,如泰國、日本和新加坡,報告的病例比其他亞洲和歐洲國家多。德國是一個例外,其擁有的病例在歐洲最多。
死亡率從未超過 3%,正在逐漸下降到 2%。未來幾周更多的康復病例可能會進一步降低這一數(shù)字。
中國湖北省是此次疫情的中心,報告的病例明顯多于其他所有省份的總和。有些省份沒有死亡病例,所有受感染的病人都康復了。
結(jié)論
分析顯示,武漢冠狀病毒的傳播速度驚人。目前,至少 811 人在此次疫情中死亡,超過 7 年前非典爆發(fā)時報告的 774 人死亡人數(shù)。我祈禱并希望病毒能盡快得到控制。
via:https://towardsdatascience.com/a-data-scientists-perspective-on-the-wuhan-coronavirus-4d1110446478
雷鋒網(wǎng)雷鋒網(wǎng)雷鋒網(wǎng)
雷峰網(wǎng)版權(quán)文章,未經(jīng)授權(quán)禁止轉(zhuǎn)載。詳情見轉(zhuǎn)載須知。