如何将带有单元格分隔符的python脚本转换为jupyter笔记本? [英] How to convert a python script with cell delimiters to a jupyter notebook?

查看:174
本文介绍了如何将带有单元格分隔符的python脚本转换为jupyter笔记本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我主要使用Spyder进行数据分析,并且对此感到非常满意.您可以在其中使用# %%在普通的python脚本中使用Jupyter Notebook的单元功能,以分隔单个代码单元(并执行块).在带有氢的原子中,同样的事情也是可能的.

我正在寻找的是一种将这些脚本转换为jupyter笔记本的方法,可以自动在每个# %%处拆分单元格.我将通过插入一些markdown并可能另存为pdf或html来记录,解释和共享我的工作流程的笔记本.

转换可以自动完成吗? nbconvert也许可行吗? (我只用另一种方式使用它:jupyter-> python)

解决方案

jupytext (也可以在 pypi )上使用),该格式可以从ipynb转换为多种格式然后再转换回.

安装jupytext后,您可以使用

$ jupytext --to notebook test.py

以便生成test.ipynb.

jupytext具有许多有趣的功能,在使用笔记本电脑时可以派上用场.

I mostly use Spyder for my data analysis and am quite satisfied with it. There you can use the cell functionality of Jupyter Notebooks in normal python scripts using # %% to delimit individual code cells (and also execute blocks). The same thing is also possible in Atom with Hydrogen.

What I am looking for is a way to convert these scripts into a jupyter notebook, automaticlally splitting cells at each # %%. The notebook I would use to document, explain and share my workflow by inserting some markdown and possibly saving as pdf or html.

Can the conversion be done automatically? Is this perhaps doable with nbconvert? (I only use it the other way around: jupyter -> python)

解决方案

there is jupytext (also available on pypi) that can convert from ipynb to several formats and back.

when jupytext is installed you can use

$ jupytext --to notebook test.py

in order to generate test.ipynb.

jupytext has a lot more interesting features that can come in handy when working with notebooks.

这篇关于如何将带有单元格分隔符的python脚本转换为jupyter笔记本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆