IPython Notebook cell multiple outputs

后端 未结 5 626
攒了一身酷
攒了一身酷 2020-12-22 17:34

I am running this cell in IPython Notebook:

# salaries and teams are Pandas dataframe
salaries.head()
teams.head()

The result is that I am

5条回答
  •  臣服心动
    2020-12-22 18:27

    An easier way:

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

    It saves you having to repeatedly type "Display"

    Say the cell contains this:

    from IPython.core.interactiveshell import InteractiveShell
    InteractiveShell.ast_node_interactivity = "all"
    
    a = 1
    b = 2
    
    a
    b
    

    Then the output will be:

    Out[1]: 1
    Out[1]: 2
    

    If we use IPython.display.display:

    from IPython.display import display
    
    a = 1
    b = 2
    
    display(a)
    display(b)
    

    The output is:

    1
    2
    

    So the same thing, but without the Out[n] part.

提交回复
热议问题