ipython notebook 隐藏代码_如何隐藏IPython Notebook中的一个特定单元格(输入或输出)?...

Is there a way to selectively hide one specific input or output cell in IPython notebook?

I could only find the below code to show / hide all input cells.

But what if I only want to hide the first input cell of a notebook?

解决方案

This is now built into nbconvert (as of 5.3.0) using tags.

Here's an example removing a specific cell from the output. Using this notebook. The example has three cells: a markdown cell, a code cell that will be hidden, and a code cell that will not be hidden.

Add the remove_cell tag to any cells you want to hide using the tag editor built into the notebook or JupyterLab (the specific name "remove_cell" doesn't matter)

Convert with nbconvert

jupyter nbconvert nbconvert-example.ipynb --TagRemovePreprocessor.remove_cell_tags='{"remove_cell"}'

Any cells with the tag remove_cell will be removed from the output.

In addition to entire cells, you can filter just inputs or just outputs:

TagRemovePreprocessor.remove_input_tags

TagRemovePreprocessor.remove_single_output_tags

TagRemovePreprocessor.remove_all_outputs_tags

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值