對(duì)于用Jupyter Notebook編寫(xiě)的python腳本,如果可以將較長(zhǎng)的代碼部分隱藏抛丽,只顯示Markdown說(shuō)明文本样漆、和代碼塊的運(yùn)行結(jié)果撞秋,便可將腳本直接用作動(dòng)態(tài)分析報(bào)告长捧。即在保持可讀性的同時(shí),可通過(guò)刷新原數(shù)據(jù)/調(diào)整代碼即時(shí)生成新的報(bào)告內(nèi)容吻贿。
實(shí)現(xiàn)顯示/隱藏代碼塊的步驟:
安裝jupyter_contrib_nbextentions
(Ref: https://jupyter-contrib-nbextensions.readthedocs.io/en/latest/install.html#install-the-python-package)
conda安裝命令:conda install -c conda-forge jupyter_contrib_nbextensions
python安裝命令:pip install jupyter_contrib_nbextensions安裝jupyter_nbextentions_contributor串结,以便在Jupyter Notebook頁(yè)面設(shè)置nbextentions
(Ref: https://github.com/Jupyter-contrib/jupyter_nbextensions_configurator)
conda安裝命令:conda install -c conda-forge jupyter_nbextensions_configurator
python安裝命令:pip install jupyter_nbextensions_configurator-
安裝完成后,點(diǎn)擊Jupyter Notebook首頁(yè)的Nbextensions標(biāo)簽舅列,打開(kāi)在Nbextensions configuration設(shè)置頁(yè)面肌割。
1)勾選Hide input(顯示/隱藏選定代碼塊)
2)勾選Hide input all(顯示/隱藏所有代碼塊)
notebook_configure_LI.jpg
-
打開(kāi)任意python腳本文件,可看到工具欄中已添加相應(yīng)的按鈕帐要。
notebook_hidecode_LI.jpg