How to clear an IPython Notebook's output in a

2019-03-14 12:00发布

I have a problem when the output from a notebook is really long and it's saved into the notebook, any time I want to open this particular notebook again the browser crashes and can't display correctly.

To fix this I have to open it with a text editor and delete all output from that cell causing the problem.

I wonder if there is a way to clean all output from the notebook so one can open it again without problem. I want to delete all output since deleting a specific one seems more troublesome.

3条回答
我只想做你的唯一
2楼-- · 2019-03-14 12:20

--ClearOutputPreprocessor.enabled=True

There is now a built-in command line option to do it:

jupyter nbconvert --ClearOutputPreprocessor.enabled=True --inplace Notebook.ipynb

Or to another file called NotebookNoOut.ipynb:

jupyter nbconvert --ClearOutputPreprocessor.enabled=True \
  --to notebook --output=NotebookNoOut Notebook.ipynb

jupyter nbconvert --help also documents a --clear-output option, but for some reason it did not work.

Tested in Jupyter 4.4.0, notebook==5.7.6.

查看更多
劫难
3楼-- · 2019-03-14 12:24

Use clean_ipynb, which not only clears notebook output but can also clean the code.

Install by pip install clean_ipynb

Run by clean_ipynb hello.ipynb

查看更多
贪生不怕死
4楼-- · 2019-03-14 12:26

Use --ClearOutputPreprocessor.enabled=True and --clear-output

Following this command:

jupyter nbconvert --ClearOutputPreprocessor.enabled=True --clear-output *.ipynb

查看更多
登录 后发表回答