10個讓你的Pandas更好用的小方法

1.使用 Pandas Profiling

2.使用Plotly讓Pandas產生互動圖形

安裝

pip install plotly 
pip install cufflinks

使用

import pandas as pd
import cufflinks as cf
import plotly.offline
cf.go_offline()
cf.set_config_file(offline=False, world_readable=True)
df.iplot()

3.Jupyter Notebook的Magic指令

%pastebin   abc.py      #上傳abc.py到pastebin並產生連結網址%matplotlib inline      #讓matplotlib產生的圖片出現在Jupyter Notebook
%matplotlib notebook #讓matplotlib產生的圖片能夠有縮放互動功能
#上方的matplotlib指令擇一使用即可%run abc.py #在Jupyter中執行abc.py
%%writefile abc.py #在程式上方加入%%writefile可以把code寫入指定檔案

4.使用%debug來除錯

%debug                 #在程式執行錯誤的下一行使用%debug來除錯

5.用pprint來美化print出來的內容

import pprint
pprint.pprint(yourVarName,width=-1)

6.使用不同顏色的Alert呈現資訊

<div class="alert alert-block alert-info">
<b>Tip:</b> Use blue boxes (alert-info) for tips and notes.
If it’s a note, you don’t have to include the word “Note”.
</div>
<div class="alert alert-block alert-warning">
<b>Example:</b> Yellow Boxes are generally used to include additional examples or mathematical formulas.
</div>
<div class="alert alert-block alert-success">
Use green box only when necessary like to display links to related content.
</div>
<div class="alert alert-block alert-danger">
It is good to avoid red boxes but can be used to alert users to not delete some important part of code etc.
</div>

7.Print所有輸入的結果,而不是只有最後一行

from IPython.core.interactiveshell import InteractiveShell  InteractiveShell.ast_node_interactivity = "all"#取消該設定
InteractiveShell.ast_node_interactivity = "last_expr"

8.用 -i 參數來幫忙Debug

python -i hello.py    #執行該指令時產生錯誤import pdb            #透過右方的程式,開啟debug模式
pdb.pm()

9.用Ctrl+/來快速產生註解

就不需要使用'''多行註解'''或是#單行註解

10.回到上一步

Ctrl+Z  #恢復cell中被刪掉的code
ESC+Z #恢復整個被刪掉的cell

Written by

Machine Learning / Deep Learning / Python / Flutter cakeresume.com/yanwei-liu

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store