Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute/Run a single line in IPython rather entire Cell

Tags:

I have often this problem, when I'm slicing or subsetting data that I want to view/print [df.head()] the data and look into into it before writing next line of my code. For this case, every time, I have to run the whole block(cell) in ipython, even if I have some logic written I had to comment that block and execute my print line alone.

Is there a feature where you can select a single line and execute it.

like image 899
Learner Avatar asked Feb 28 '14 12:02

Learner


People also ask

How do you run only one line in a Jupyter notebook?

Run > Run Selected Text or Current Line in Console , optionally with a keyboard shortcut.

How do I run line of code in Jupyter?

To run a piece of code, click on the cell to select it, then press SHIFT+ENTER or press the play button in the toolbar above. Additionally, the Cell dropdown menu has several options to run cells, including running one cell at a time or to run all cells at once.

What does %% capture do?

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.


1 Answers

I often start a qtconsole attached to the kernel. You can do that as follows:

  1. Create a new cell.
  2. In the new cell, type %qtconsole and execute that cell.
  3. Delete the new cell.

Once you have a qtconsole that is attached to the notebook kernel. You can print the value of variables there.

like image 147
David Smith Avatar answered Oct 07 '22 08:10

David Smith