iPython笔记本不打印Dataframe作为表 [英] iPython Notebook not printing Dataframe as table
本文介绍了iPython笔记本不打印Dataframe作为表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在ipython笔记本中打印一个df,但不会将其打印为表格。
I'm trying to print a df in ipython notebook but it doesn't print it as a table.
data = {'year': [2010, 2011, 2012, 2011, 2012, 2010, 2011, 2012],
'team': ['Bears', 'Bears', 'Bears', 'Packers', 'Packers', 'Lions', 'Lions', 'Lions'],
'wins': [11, 8, 10, 15, 11, 6, 10, 4],
'losses': [5, 8, 6, 1, 5, 10, 6, 12]}
football = pd.DataFrame(data, columns=['year', 'team', 'wins', 'losses'])
print football
输出
year team wins losses
0 2010 Bears 11 5
1 2011 Bears 8 8
2 2012 Bears 10 6
3 2011 Packers 15 1
4 2012 Packers 11 5
5 2010 Lions 6 10
6 2011 Lions 10 6
7 2012 Lions 4 12
我尝试显示为建议在iPython Notebook中打印DataFrame表格:
from IPython.display import display
#.....
print display(football)
还试过: p>
Also tried:
pandas.core.format.set_printoptions(notebook_repr_html=True)
但是有错误:
AttributeError: 'module' object has no attribute 'set_printoptions'
如何使用漂亮的垂直和水平线打印df作为表? p>
How can I print my df as a table with nice vertical and horizontal lines?
推荐答案
set_printoptions
已被替换为 set_options
在最新版本的大熊猫中,尝试使用:
set_printoptions
has been replaced by set_options
in the more recent versions of pandas, try to use:
pandas.set_option('display.notebook_repr_html', True)
也不要使用 print
,只需在no的最后一行状态 football
或 display(football)
tebook cell。
Also do not use print
, simply state football
or display(football)
in the last line of a notebook cell.
这篇关于iPython笔记本不打印Dataframe作为表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文