0

I prepared a jupyter notebook that is a python template for a report. It displays pandas dataframes and plots some charts. After execution, I want to save it either in html or pdf format. In the first cell I initialize the variable month = 2.

My question is can I automatically make it run several times for months from collection [1,2,5,6] and store each execution as a html file?

miepsik
  • 63
  • 8

1 Answers1

1

I would advise to put the code that generates the report inside a function. Then call the function from a loop. Which loops over an array of the different parameters you want to pass along each report. Then you just run your notebook once.

Otherwise pass the parameters to your notebook described here: Passing command line arguments to argv in jupyter/ipython notebook

and then export to html like so: https://stackoverflow.com/a/38909626/9268396

  • Papermill that is listed among the options at the page Thomas Guntenaar references is nice for this. You can have a controlling notebook (or script) that kicks off running the versions with your parameters. Other options also along the line of what Thomas suggest in his first paragraph is to use code in a notebook or script along with [nbformat](https://nbformat.readthedocs.io/en/latest/api.html#) to make the versions of the notebooks and then use `jupyter nbconvert` or `jupytext` to execute each. – Wayne May 25 '22 at 15:40