Display() in Python

心已入冬 提交于 2020-08-19 02:54:42

问题


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?


回答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. IPyhton 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



回答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


来源:https://stackoverflow.com/questions/49328447/display-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!