2

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.

Lisa
  • 4,126
  • 12
  • 42
  • 71

2 Answers2

2

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

Community
  • 1
  • 1
LinkBerest
  • 1,281
  • 3
  • 22
  • 30
1

Another option which requires less mouse movement and clicks than JGreenwell's answer, especially if you prefer accomplishing this with speedy keyboard work like I would:

  1. Click in cell #1
  2. Select all code (Ctrl+A)
  3. Comment-out code (Ctrl+/)
  4. Go to next cell (Shift+Enter) -- will execute cell, but is meaningless since all code is commented
  5. Repeat steps 2-4 until cell #5
  6. Select cell #200 and select Run All Above
  7. Go back and un-comment cell 1-5 (Ctrl+A, Ctrl+/)

You can easily move between cells using the keyboard: Press Esc (command mode), Press J (up) or K (down) to select adjacent cell. Press Enter (to enter the code). Then press Ctrl+A then Ctrl+/ to un-comment. Repeat from Esc.

Qululu
  • 1,040
  • 2
  • 12
  • 23