Lisa Lisa - 1 month ago 6
Python Question

how to run jupyter notebook from 5th cell to 100th cell, without running other part of the notebook?

Say I have a jupyter nootebook with 200 cells.

how to run from 5th cell to 100th cell, without running other part of the notebook?

Now I commend out 101th-200th and 1st-4th cell. I'm sure it is not the best practise.

Answer

One cannot just run cells 5 thru 100 easily with the Jupyter notebook but there are a few options. The first is just selecting each cell and running Merge Cell Above from the edit menu then just running the new cell. The second, and best way I've found to do this is:

  1. First select the top cells to be ignored (or bottom if there are less on the bottom) and change the Cell Type to Raw NBConvert to prevent IPython from interpreting it.

jupyter notebook menu Cell->Cell Type->Raw NB

  1. Go to the cell after the one you want to run and select Run All Above (or below if less there).

menu Cell->Run All Above

Now you've only run those middle cells and can just go back and reset the cell type to code (instead of having to comment and then un-comment) and keep going.

* If you are using NBViewer you can hide the code or just set it to Markdown