简体   繁体   English

iPython Notebook不将数据框打印为表格

[英]iPython Notebook not printing Dataframe as table

I'm trying to print a df in ipython notebook but it doesn't print it as a table. 我正在尝试在ipython笔记本中打印df,但它不会将其打印为表格。

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

Output 产量

   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

I tried "display" as suggested Show DataFrame as table in iPython Notebook : 我按照建议在iPython Notebook中将 “显示数据” 显示为表时尝试“显示”:

from IPython.display import display
#.....
print display(football)

Also tried: 还尝试了:

pandas.core.format.set_printoptions(notebook_repr_html=True)

but got error: 但出现错误:

AttributeError: 'module' object has no attribute 'set_printoptions'

How can I print my df as a table with nice vertical and horizontal lines? 如何将df打印为具有良好的垂直和水平线的表格?

set_printoptions has been replaced by set_options in the more recent versions of pandas , try to use: set_printoptions已取代set_options在较新版本的熊猫 ,尝试使用:

pandas.set_option('display.notebook_repr_html', True)

Also do not use print , simply state football or display(football) in the last line of a notebook cell. 也不要使用print ,只需在笔记本单元格的最后一行声明footballdisplay(football)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM