Display() in Python

Matt Wonderwall picture Matt Wonderwall · Mar 16, 2018 · Viewed 58.5k times · Source

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?

Answer

piRSquared picture piRSquared · Mar 16, 2018

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