Needless to say, the last value of the cell is automatically output. Depending on the value, it can be output in a form that is easier to see than a character string. A typical one is pandas DataFrame.
Notebook
from bokeh.sampledata import iris #Sample data included in Bokeh
df = iris.flowers
df.head()
Two or more values can be output by making them tuples, but the output will be a character string.
Notebook
df.head(), df.tail()
( sepal_length sepal_width petal_length petal_width species
0 5.1 3.5 1.4 0.2 setosa
1 4.9 3.0 1.4 0.2 setosa
2 4.7 3.2 1.3 0.2 setosa
3 4.6 3.1 1.5 0.2 setosa
4 5.0 3.6 1.4 0.2 setosa,
sepal_length sepal_width petal_length petal_width species
145 6.7 3.0 5.2 2.3 virginica
146 6.3 2.5 5.0 1.9 virginica
147 6.5 3.0 5.2 2.0 virginica
148 6.2 3.4 5.4 2.3 virginica
149 5.9 3.0 5.1 1.8 virginica)
Needless to say, the print function. If you use this, you can output the value even in the middle of the cell. However, it is a pity that only character strings can be output.
Notebook
from bokeh.sampledata import iris
df = iris.flowers
print(df.head())
print(df.tail())
sepal_length sepal_width petal_length petal_width species
0 5.1 3.5 1.4 0.2 setosa
1 4.9 3.0 1.4 0.2 setosa
2 4.7 3.2 1.3 0.2 setosa
3 4.6 3.1 1.5 0.2 setosa
4 5.0 3.6 1.4 0.2 setosa
sepal_length sepal_width petal_length petal_width species
145 6.7 3.0 5.2 2.3 virginica
146 6.3 2.5 5.0 1.9 virginica
147 6.5 3.0 5.2 2.0 virginica
148 6.2 3.4 5.4 2.3 virginica
149 5.9 3.0 5.1 1.8 virginica
If you use the display function instead of the print function, you can print in the middle of the cell in the same easy-to-read format as the last value in the cell.
Notebook
from IPython.display import display
from bokeh.sampledata import iris
df = iris.flowers
display(df.head(), df.tail())
If you don't want to use the display function, you can set it to output all values. However, note that it is necessary to set in advance in a cell different from the cell where you want to output.
Notebook
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
Notebook
from bokeh.sampledata import iris
df = iris.flowers
df.head()
df.tail()
To return to the original state, substitute the default value 'last_expr'
for ʻast_node_interactivity`.
Notebook
InteractiveShell.ast_node_interactivity = 'last_expr'
Recommended Posts