Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy multiple input cells in Jupyter Notebook

Basically I want to copy (Ctrl+C) only the code portions from multiple cells without also copying the output or the In[1]: and Out[1]:

What is the easiest way to do so?

like image 792
Vic Avatar asked Sep 21 '17 02:09

Vic


People also ask

What is %% capture in Jupyter?

What does %% capture do in Jupyter? Capturing Output With %%capture IPython has a cell magic, %%capture , which captures the stdout/stderr of a cell. With this magic you can discard these streams or store them in a variable. By default, %%capture discards these streams. This is a simple way to suppress unwanted output.

How do you clone in Jupyter Notebook?

In the JupyterLab folder File Browser, select the folder where you want to clone the GitHub repository. For example, the home folder. Click the Git clone button. In the Clone a repo dialog, paste the URL for your GitHub repository that you copied earlier.

Can Jupyter Notebook autofill?

Enable autocomplete featureTo enable code autocomplete in Jupyter Notebook or JupyterLab, you just need to hit the Tab key while writing code. Jupyter will suggest a few completion options. Navigate to the one you want with the arrow keys, and hit Enter to choose the suggestion.


2 Answers

When you are on a cell in Command mode(blue color mode), simply press Shift + DownArrow or Shift + UpArrow to select multiple cells. Press ctrl + C. And that's it. You have copied your entire selected code at once. It doesn't affect whether you have cell outputs.

Command mode: The Jupyter Notebook has two different keyboard input modes. Edit mode allows you to type code or text into a cell and is indicated by a green cell border. Command mode binds the keyboard to notebook level commands and is indicated by a grey cell border with a blue left margin.

like image 155
Lahiru Karunaratne Avatar answered Sep 22 '22 14:09

Lahiru Karunaratne


In jupyter you can copy several cells or the content of one cell. If you follow @BenWS comment you can copy several cells, and if you do kernel > restart & clear outputs beforehand you woult not get the [out]. Shortcut is C for copy cell and V shift + V to paste below / above.

However if you intend to copy several cells content, you should merge then before by select them and shift + M and then you can copy paste with ctrl + C.

like image 39
MCMZL Avatar answered Sep 20 '22 14:09

MCMZL