農林漁牧網

您現在的位置是:首頁 > 林業

快速掌握資料分析必備工具,ipython和jupyter notebook

2023-01-12由 CDA資料分析師 發表于 林業

ipynb檔案用什麼開啟

作者:麥叔

快速掌握資料分析必備工具,ipython和jupyter notebook

本文幫你快速掌握資料分析師必須會用的兩個工具 - ipython和jupyter notebook。

既然有了Python,為什麼還要ipython?麥叔不用說話,給你一張圖你就明白啦。jupyter notebook又是什麼鬼?

建議把本文放到收藏夾。吃灰也好過需要的時候找不到。

一、iPython

iPython是

Interactive Python

,它是基於Python的一個包裝。它其實就是一個可以透過pip安裝的包。提供了普通python之外的一些功能,其中一個功能就是可以顯示圖片。

快速掌握資料分析必備工具,ipython和jupyter notebook

iPython在資料分析師,資料科學家,人工智慧科學中經常使用。

(1)安裝

python -m pip install ipython

(2)使用

ipython就是Python,使用方法和使用普通的互動式Python一樣,程式碼也一樣。只不過輸出顯示上有一定最佳化。

1。進入ipython:

zjueman@maishudata_analysis%ipythonPython3。8。1(v3。8。1:1b293b6006,Dec182019,14:08:53)Type‘copyright’,‘credits’or‘license’formoreinformationIPython7。21。0——AnenhancedInteractivePython。Type‘?’forhelp。In[1]:

2。使用ipython:為了執行一下程式碼,請先安裝numpy:

python -m pip install numpy

In[1]:a=5In[2]:b=“麥叔”In[3]:importnumpyasnpIn[4]:data={i:np。random。randn()foriinrange(7)}In[5]:dataOut[5]:{0:0。8738401705018338,1:0。7173530856483666,2:1。269301701227684,3:-0。6322949353286054,4:-2。3619895093818295,5:-0。9031446928993554,6:-0。07942775508126601}

3。問號尋求幫助:

In [4]: name = ‘maishu’In [5]: name?Type: strString form: maishuLength: 6Docstring: str(object=‘’) -> strstr(bytes_or_buffer[, encoding[, errors]]) -> strCreate a new stringobjectfrom the given object。 If encoding orerrors is specified, then the object must expose a data bufferthat will be decoded using the given encoding and error handler。Otherwise, returns the result of object。__str__() (if defined)or repr(object)。encoding defaults to sys。getdefaultencoding()。errors defaults to ‘strict’。

4。退出

In[10]: quit()zjueman@maishu data_analysis %

5。畫圖 為了執行一下程式碼需要先安裝matplotlib

python -m pip install matplotlib

In[1]: importnumpyasnpIn[2]: %matplotlibUsingmatplotlibbackend: MacOSXIn[3]: importmatplotlib。pyplotaspltIn[4]: plt。plot(np。random。randn(50)。cumsum())Out[4]: [

快速掌握資料分析必備工具,ipython和jupyter notebook

二、jupyter notebook

資料科學家們覺得ipython還不夠過癮,又在ipython基礎上開發了jupyter notebook:一個基於網頁的寫程式碼介面。

快速掌握資料分析必備工具,ipython和jupyter notebook

jupyter是基於ipython的,很多操作幾乎都一樣。但是它有很多獨特優點:

(1)檔案可以儲存為ipynb的檔案

(2)線上編寫程式碼

(3)支援多人協作

(4)支援markdown格式的文件

1。 安裝

python -m pip install jupyter

2。 啟動

> jupyter notebook

這個命令會在本機的8888埠上執行一個網站,並自動開啟瀏覽器:

http://localhost:8888/tree

快速掌握資料分析必備工具,ipython和jupyter notebook

3。 基本使用

(1)建立檔案

快速掌握資料分析必備工具,ipython和jupyter notebook

(2)編寫和執行程式碼

快速掌握資料分析必備工具,ipython和jupyter notebook

(3)儲存和修改檔名

快速掌握資料分析必備工具,ipython和jupyter notebook

檔案儲存在你開啟jupyter notebook的目錄下:

檔案的格式是ipynb

快速掌握資料分析必備工具,ipython和jupyter notebook

4。 Tab補全

在notebook中打程式碼的過程中,按Tab鍵可以自動提示和補全,類似於Pycharm和VSCode等IDE的功能:

快速掌握資料分析必備工具,ipython和jupyter notebook

它可支援:

(1)自動補全變數名

(2)自動補全函式名

(3)自動補全檔名等

5。 整合matplotlib畫圖

快速掌握資料分析必備工具,ipython和jupyter notebook

6。 魔術命令

(1)執行指令碼:%run

(2)列印命令輸入歷史:%hist

(3)執行效率:%timeit

(4)其他魔術命令

快速掌握資料分析必備工具,ipython和jupyter notebook

7。 快捷鍵

(1)停止執行:Ctrl+C

(2)其他ipython快捷鍵

快速掌握資料分析必備工具,ipython和jupyter notebook