Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ipython Notebook: how to run multiple cells?

My notebook gets a bit of long, I divide it into several parts. Sometimes, I just want to run a certain part of it, i.e consecutive cells

For example, enter image description here

I want to run Cell IN [52] to[54], not run IN [51],[59]. How can I do it?

I only know there is option for run above, run below, I didn't see anything like run selected cells.


UPDATE: Now Jupyter Notebook has this feature built-it, simply CTRL + click

enter image description here

like image 350
cqcn1991 Avatar asked Nov 23 '15 06:11

cqcn1991


3 Answers

UPDATE as per Jan 2018: You can select and run multiple cells in command mode using the below shortcuts:

1.shift+K (select the cells in an upward direction) and then Ctrl+Enter

2.shift+J (select the cells in a downward direction) and then Ctrl+Enter

like image 193
karthik prasanna Avatar answered Oct 02 '22 13:10

karthik prasanna


I found a useful extension that performs a similar function: init_cell. First, you will need to install jupyter nbextensions configurator as described here.

Then search for "Initialization cells" from inside the search bar of the Jupyter nbextension manager.

A check box at the top of every cell will appear. You can select which cells to be marked as initialization cells.

To run all the initialization cells at once, click the button with calculator symbol on the tool bar: Initialization cells extension

Along with cqcn1991's solution, you can gain a reasonable control over your notebook.

like image 34
O. Salah Avatar answered Oct 02 '22 14:10

O. Salah


I know this is not the answer your are looking for (because its not the answer I was looking for) but for your specific case of running cells 52-54, because they are sequential and continuous, you can simply click the play button (run cell and select below) 3 times

enter image description here

and it will queue those cells for running. This will work for a handful of sequential cells, but for out of sequence or really long blocks of cells, probably not the best ideal

like image 1
Vince W. Avatar answered Oct 02 '22 15:10

Vince W.