力壓 R,Python 在數(shù)據(jù)科學(xué)領(lǐng)域風(fēng)生水起
TIOBE 最新發(fā)布的 9 月編程語言排行榜中,Python 憑 4.67% 的增速以 0.26% 的優(yōu)勢力壓 C++,逆襲成功進(jìn)入 Top 3。
而近一年勢頭不滅的 Python 在數(shù)據(jù)分析領(lǐng)域,是專家們的必備技能。隨著 IT 行業(yè)的增長,對有經(jīng)驗(yàn)的數(shù)據(jù)科學(xué)家的需求也水漲船高,而 Python 也一躍而成最受歡迎的語言。本文旨在介紹分析數(shù)據(jù)的基本知識,并利用 Python 創(chuàng)建一些漂亮的數(shù)據(jù)可視化。
概要
數(shù)據(jù)科學(xué)領(lǐng)域,非 Python 語言莫屬?
Python 是最適合數(shù)據(jù)科學(xué)家的語言,這一點(diǎn)毫無爭議。下面幾點(diǎn)可以幫你理解為什么從事數(shù)據(jù)科學(xué)的人選擇了 Python:
你知道最大的好處是什么嗎?數(shù)據(jù)科學(xué)家是目前收入最高的職位之一,根據(jù) Indeed.com 的數(shù)據(jù),平均年薪為 $130,621。
Python 由 Guido Van Rossum 于 1989 年創(chuàng)建。它是個(gè)解釋語言,擁有動(dòng)態(tài)語義。它在所有的平臺上可以免費(fèi)使用。Python 是:

為數(shù)據(jù)科學(xué)中的 Python 安裝 Jupyter
我們先來在自己的系統(tǒng)上安裝 Jupyter。請按照以下步驟進(jìn)行:
我建議你使用 Anaconda 發(fā)行版(https://www.anaconda.com/download/)安裝 Python 和 Jupyter。裝好Jupyter 之后,可以在命令行中輸入“Jupyter Notebook”即可在默認(rèn)瀏覽器中打開?,F(xiàn)在我們在 Jupyter 上寫個(gè)最基本的程序。
- name=input( "Enter your Name:")
- print( "Hello", name)
要運(yùn)行這段代碼,可以按下“Shift+Enter”,即可查看輸出。如下面的截圖所示:

數(shù)據(jù)科學(xué)中的 Python 的基礎(chǔ)
現(xiàn)在可以開始編程了。為了編程,你需要先了解以下的基礎(chǔ)知識:
關(guān)于 Python的更多信息和實(shí)際的實(shí)現(xiàn),可以參考這篇文章:Python 入門(https://www.edureka.co/blog/python-tutorial/)。
數(shù)據(jù)科學(xué)中的 Python 庫
這是 Python 在數(shù)據(jù)科學(xué)中發(fā)揮力量的部分。Python 擁有大量用于科學(xué)計(jì)算、分析、可視化等的庫。一些庫如下:
Demo:實(shí)際應(yīng)用
問題描述:給定一組數(shù)據(jù)集,該數(shù)據(jù)集是由多種數(shù)據(jù)組成的綜合統(tǒng)計(jì)數(shù)據(jù),如監(jiān)獄設(shè)施的分布和情況、監(jiān)獄的擁擠程度、監(jiān)獄中的犯人類型,等等。請?jiān)谶@個(gè)數(shù)據(jù)集上做描述性的統(tǒng)計(jì),并從數(shù)據(jù)中找出有用的信息。下面是幾個(gè)任務(wù):
加載數(shù)據(jù)使用以下代碼:
- importpandas aspd
- importmatplotlib.pyplot asplot
- %matplotlib inline
- file_name = "prisoners.csv"
- prisoners = pd.read_csv(file_name)
- prisoners

然后用 Pandas 的 describe 方法,只需輸入以下語句:
- prisoners.describe()

然后進(jìn)行數(shù)據(jù)操作:
- prisoners[ "total_benefited"]=prisoners.sum(axis=1)
- prisoners.head()

最后,用 Python 做一些數(shù)據(jù)可視化。代碼如下:
- importnumpy asnp
- xlabels = prisoners[ 'STATE/UT'].values
- plot.figure(figsize=( 20, 3))
- plot.xticks(np.arange(xlabels.shape[ 0]), xlabels, rotation = 'vertical', fontsize = 18)
- plot.xticks
- plot.bar(np.arange(prisoners.values.shape[ 0]),prisoners[ 'total_benefited'],align = 'edge')
