在IPython / Jupyter笔记本中导出个别单元格 [英] Export individual cell in IPython/Jupyter notebook
问题描述
我可以将整个笔记本导出为HTML,但是我只想导出一个单元格以及其输出。
有没有一些方法这样做?
一种方法是使用自定义预处理器。
我解释了如何简单地回应简单的方法来选择在运行所有的ipython笔记本中运行的单元格。总结一下:您可以扩展 nbconvert.preprocessors.ExecutePreprocessor
来创建一个预处理器,用于检查单元格元数据以确定是否该单元格应该被执行和/或输出。
我一直使用Jupyter笔记本进行报告生成,所以我写了一个自定义处理器的集合来扩展nbconvert行为:
- 元语言,以确定哪些单元格被执行并包含在最终报告中(如果整个笔记本电脑部分的if else else逻辑)
- 执行代码从输出中删除代码单元的标记单元格
- 从命令行输入参数
我没有时间包装这些在可分发的分机中,您可以在此处查看代码: https://gist.github.com/brazilbean / 3ebb31324f6dad212817b3663c7a0219 。
请随时与这些示例一起使用/修改/做好事情。 :)
I am able to export the entire notebook as HTML, but I would like to export just a single cell, together with its output.
Is there some way of doing this?
One way to do this is to use a custom preprocessor.
I explain how to do this briefly in response to Simple way to choose which cells to run in ipython notebook during run all.
To summarize: you can extend nbconvert.preprocessors.ExecutePreprocessor
to create a preprocessor that checks cell metadata to determine whether that cell should be executed and/or output.
I use Jupyter Notebooks for report generation all the time, so I wrote a collection of custom processors to extend nbconvert behavior:
- meta-language to determine what cells get executed and included in the final report (if/else logic on entire notebook sections)
- executing code in markdown cells
- removing code cells from output.
- taking input arguments from the command line
I haven't had time to wrap these in an distributable extension, but you can see the code here: https://gist.github.com/brazilbean/3ebb31324f6dad212817b3663c7a0219.
Please feel free to use/modify/do-great-things with these examples. :)
这篇关于在IPython / Jupyter笔记本中导出个别单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!