How do I reset the Jupyter/IPython input prompt numbering?
Solution 1
I think, the only way to to what you want is: - 'Kernel > Restart' (restart the kernel) and then 'Cell > Run All' (run the script).
Solution 2
Every .ipynb
file can be opened in an editor. Everything written there is in plain text (JSON). For each cell which has the "cell_type": "code"
there'd be another key-value pair as "execution_count": <number>
. As you might have guessed, that is the prompt numbering. Hence, if the notebook contains code which will take time to execute (as was, in my case) this method would be time efficient.
Now, either you can manually change each execution_count
or write a simple script to get the numbering right. To check the results just refresh the notebook in the browser without stopping the kernel. And, everything will be as per your needs, even all the variables/loaded data will remain in the environment.
Solution 3
You can reset the kernel (shortcut: C-m .
) and re-run the whole notebook.
Quitting and reloading doesn't work because the code is not re-evaluated.
Solution 4
'Kernel' -> 'Restart & Run All'
Just make sure you saved your Notebook. You can also bind/assign keyboard key for running this command.
'Help' -> 'Edit Keyboard Shortcuts'
Solution 5
If what you want is to remove the numbers themselves, so that each cell shows In [ ]
(instead of something like In [247]
which is leftover from some previous incarnation of the kernel), use "Cell" > "All Output" > "Clear" (in Jupyter Notebook 5.4.0) or "Edit" > "Clear All Outputs" (In Jupyter Lab 0.32.1).
This will remove all the numbers, even if you're in the middle of running a notebook. It will not reset the numbering back to 1; e.g. if the last cell you executed was 18, the next will be 19.
If you're using this because you want clarity about which cells you've executed during this run of the kernel and which cells you haven't executed yet, use "Cell" > "All Output" > "Clear" (or "Edit" > "Clear All Outputs") immediately after you start (or restart) the kernel. This can be useful when restarting a kernel, or when opening a saved or duplicated notebook.
This will also remove all outputs from the notebook.
Thanks to user2651084 in a previous comment for this.
Related videos on Youtube
user2651084
Updated on August 30, 2020Comments
-
user2651084 over 3 years
I just wrote my first extensive Python tutorial using IPython notebooks. All went well, except I did a lot of testing and moving blocks around. How do I reset the
In [ ]:
numbering? I have tried quitting and reloading, but that doesn't seem to work. -
user2651084 over 10 yearsI just figured it out. In the menu Cell > All Output > Clear
-
Duff over 8 yearsExactly what I was looking for. Thanks!
-
mimoralea over 8 years
Cell > All Output > Clear
just clears the output, it doesn't reset the numbering...Kernel > Restart
does it. -
Michael Szczepaniak almost 7 yearsThere is now an option under Kernel "Restart & Run All" which does the same thing with a single click now as Vlad Bezden mentions below.
-
NuValue over 5 yearsAnother valid option that clears all those numbers at the left side is on the top bar: >"Kernel" >"Restart and Clear Output". you then confirm by clicking "Restart and Clear All Outputs" and you´ll have the same notebook, but without any input numerations.
-
Julian Drago almost 5 years+1, for those of us who came here asking how we can reset the execution numbers without rerunning the entire notebook.
-
aderchox almost 5 yearsthanks! I added "Ctrl-Shift-R" to "restart kernel and run all cells".
-
ijoseph almost 5 years@JulianDrago Yeah, my notebooks take hours or even days to run sometimes… restarting kernel certainly not usually an option merely just to reset execution numbers.
-
gbeaven about 3 yearsThis does not answer the question.
-
ssp over 2 yearsFor those who want to search-replace via regex:
(?<=("execution_count": ))\d+