Display() in Python

131,971

Solution 1

display is a function in the IPython.display module that runs the appropriate dunder method to get the appropriate data to ... display. If you really want to run it

from IPython.display import display
import pandas as pd

data = pd.DataFrame(data=[tweet.text for tweet in tweets], columns=['Tweets'])

display(data.head(10))

But don't. IPython is already doing that for you. Just do:

data.head(10)

You even might have IPython uninstalled, try:

pip install IPython

or if running pip3:

pip3 install IPython

Solution 2

To solve the problem on pycaret, you have to open the below file -

..\env\Lib\site-packages\pycaret\datasets.py

and add the line of code -

from IPython.display import display
Share:
131,971

Related videos on Youtube

Matt Wonderwall
Author by

Matt Wonderwall

Updated on July 09, 2022

Comments

  • Matt Wonderwall
    Matt Wonderwall almost 2 years

    I'm trying to get my data head to display but I get an error message: NameError: name 'display' undefined

    import pandas as pd
    data = pd.DataFrame(data=[tweet.text for tweet in tweets], columns=['Tweets'])
    
    display(data.head(10))
    

    Any ideas on how to fix this?

    • cs95
      cs95 about 6 years
    • hpaulj
      hpaulj about 6 years
      The normal Python3 display is : print(data). Or in an interactive session just type data.
    • BSalita
      BSalita almost 4 years
      This question became relevant when I used VSCode to convert .ipynb to .py. The line from IPython.display import display was needed.
  • LabGecko
    LabGecko almost 5 years
    Shouldn't the solution be on top to avoid confusion? "IPython is already doing that for you. Just do:..."
  • hpchavaz
    hpchavaz over 2 years
    Under Jupyter, display is quite use full as its notably if you use pandas, when you need to display multiple objets: displayproduces the full representation where print bings only the text one.