Remove cells from Jupyter Notebook with nbconvert

两盒软妹~` 提交于 2019-12-04 06:04:47

You need to enable the TagRemovePreprocessor before you call it.

The code below shows how to enable it and how to enclose your tags as a list so you can exclude more than one tag if you wish. To exclude a single tag, just put one element in the list eg ['remove_cell'].

The parameter --to html is not required if you are converting to html (as html is the default). If you want to convert to python, for example, change --to html to --to python

jupyter nbconvert a.ipynb --TagRemovePreprocessor.enabled=True --TagRemovePreprocessor.remove_cell_tags="['remove_cell', 'other_tag_to_remove']" --to html

Note that the TagRemovePreprocessor is only available in nbconvert 5.3 and above: https://nbconvert.readthedocs.io/en/latest/changelog.html?highlight=TagRemovePreprocessor

Needs some extra quoting to work:

--TagRemovePreprocessor.remove_cell_tags={\"remove_cell\"}.

However beware of an ongoing issue with noteboot to notebook conversion - it seems like in this case preprocessors, including tag removal, do not run. See more in this SO question:

jupyter nbconvert --to notebook not excluding raw cells

Update: Not tested on windows, just on Linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!