我有一个Python/Pandas脚本,将生成一些我想要的报告。目前,NBConvert将始终将文件另存为我的iPython笔记本的标题。理想情况下,如果我的报告是关于汽车的,我想要一辆法拉利,福特,特斯拉,...每个报告都以各自的公司名称Ferrari.html、Ford.html、Tesla.html、....重要的是,这一切都是从一个笔记本"Car_Data.ipynb“创建的。
我已经阅读了这里的文档:NBConvert Documentation
这说明:“由nbconvert创建的输出文件将具有与notebook相同的基本名称,并将放置在当前工作目录中。”
有没有人知道有一种方法可以从iPython笔记本中编写这种类型的HTML输出脚本。
目前,我已经实现了以下代码,以当前文件名保存当前的notebook:
#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感谢您的帮助!
发布于 2014-09-30 02:25:48
下面是如何插入您自己的文件名并使用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发布于 2021-06-15 05:19:36
如果任何人想做同样的事情,请查看造纸厂图书馆。它可以运行一台笔记本电脑,并在飞行中更改参数。
import papermill as pm
notebook_to_execute = 'index.ipynb'
notebook_filename = 'test.ipynb' # This file will be created by papermill
pm.execute_notebook(notebook_to_execute,
notebook_filename,
parameters={'your_variable':'test1',
'your_second_variable':f'test2'})https://stackoverflow.com/questions/26105705
复制相似问题