Python中的显示()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49328447/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 19:03:09  来源:igfitidea点击:

Display() in Python

pythonipythondisplay

提问by Matt Wonderwall

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

我试图让我的数据头显示,但我收到一条错误消息: 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?

有想法该怎么解决这个吗?

回答by piRSquared

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

displayIPython.display模块中的一个函数,它运行适当的 dunder 方法以获取适当的数据以...显示。如果你真的想运行它

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

但是不要。IPyhton 已经为您做到了。做就是了

data.head(10)


You even might have IPython uninstalled, try:

您甚至可能卸载了 IPython,请尝试:

pip install IPython

or if running pip3:

或者如果运行 pip3:

pip3 install IPython