我有一个 Python/Pandas 脚本,可以生成一些我想要的报告。目前,NBConvert 始终将文件保存为我的 iPython 笔记本的标题。理想情况下,如果我的报告是关于汽车主题的,我想要一份 [Ferrari、Ford、Tesla,...] 报告,每个报告都保存在各自的公司名称下 [Ferrari.html、Ford.html、Tesla.html,...] 。重要的是,这都是从一个笔记本“Car_Data.ipynb”创建的。
我已阅读此处的文档:NBConvert Documentation
这说明:“nbconvert 创建的输出文件将具有与笔记本相同的基本名称,并将放置在当前工作目录中。”
有谁知道如何从 iPython 笔记本编写此类 HTML 输出的脚本。
目前,我已经实现了下面的代码,它将当前笔记本保存在当前文件名下:
#This is a script sourced from: http://stackoverflow.com/questions/19067822/save-ipython-notebook-as-script-programmatically to save our notebook as HTML
try :
if(__IPYTHON__) :
!ipython nbconvert --to html Cluster_Availability_Charts.ipynb;
except NameError :
pass
感谢您的帮助!
最佳答案
以下是如何插入您自己的文件名并使用 iPython + NBConvert 保存笔记本:
#This is a script sourced from: http://stackoverflow.com/questions/19067822/save-ipython-notebook-as-script-programmatically to save our notebook as HTML
prefix = u'ipython nbconvert --to html --output ' #Trailing space needed
mystr = u'filename_without_html ' #Trailing space needed
suffix = u'My_Notebook.ipynb'
total = prefix + mystr + suffix
print total
try :
if(__IPYTHON__) :
get_ipython().system(total)
except NameError :
pass
关于python - 编写 NBConvert 脚本以输出到多个 HTML 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26105705/