Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

run multi command in the same jupyter cells

I'm trying to display 2 output of 2 lines in the same time, I use Panda library and it seems like it display only the output of second line:

import pandas as pd
data = {"state": ["Ohio", "Ohio", "Ohio", "Nevada", "Nevada"],
     "year": [2000, 2001, 2002, 2001, 2002],
     "pop": [1.5, 1.7, 3.6, 2.4, 2.9]}

frame = pd.DataFrame(data)

this is My cell:

frame.state
frame.year

and this is the outputs:

enter image description here

like image 735
HISI Avatar asked Dec 30 '17 18:12

HISI


People also ask

How do you run multiple cells in a Jupyter notebook at the same time?

Use the following smart shortcuts to quickly run the code cells: Ctrl+Enter : Runs the current cell. Shift+Enter : Runs the current cell and select the cell below it. To execute all code cells in your notebook, click. on the notebook toolbar or press Ctrl+Alt+Shift+Enter .

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.

Can Jupyter notebook run parallel?

We can run different tasks or processes simultaneously by using multiple computing resources during parallel notebook executions.


2 Answers

You can run a cell with this at the beginning of the notebook:

from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"

This will run all the expressions in each cell. If you want to return to the default behavior, you can write:

InteractiveShell.ast_node_interactivity = "last_expr"
like image 58
Oriol Mirosa Avatar answered Oct 18 '22 19:10

Oriol Mirosa


If you want to provide two outputs at the same time you can try doing it this way. type this on your jupyter notebook cell,

frame.state , frame.year

Just insert a comma in between it will print Output for both the statements.

like image 43
VrushM Avatar answered Oct 18 '22 19:10

VrushM