iPython Notebook 不将 Dataframe 打印为 table

iPython Notebook not printing Dataframe as table

我正在尝试在 ipython 笔记本中打印 df,但它没有将其打印为 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

我按照建议尝试了 "display" Show DataFrame as table in iPython Notebook:

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

也尝试过:

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

但出现错误:

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

如何将我的 df 打印为 table 并具有漂亮的垂直和水平线条?

set_printoptionspandas的较新版本中已被set_options取代,尝试使用:

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

也不要使用 print,只需在笔记本单元格的最后一行声明 footballdisplay(football)