iPython Notebook没有将Dataframe打印为表格

Boo*_*d16 2 python dataframe pandas ipython-notebook

我正在尝试在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
Run Code Online (Sandbox Code Playgroud)

产量

   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
Run Code Online (Sandbox Code Playgroud)

我尝试将"显示" 显示为iPython Notebook中的Show DataFrame表:

from IPython.display import display
#.....
print display(football)
Run Code Online (Sandbox Code Playgroud)

还尝试过:

pandas.core.format.set_printoptions(notebook_repr_html=True)
Run Code Online (Sandbox Code Playgroud)

但得到了错误:

AttributeError: 'module' object has no attribute 'set_printoptions'
Run Code Online (Sandbox Code Playgroud)

如何将df打印成具有漂亮垂直和水平线条的桌子?

Mar*_*erg 6

set_printoptionsset_options在最近的熊猫版本中已被替换,尝试使用:

pandas.set_option('display.notebook_repr_html', True)
Run Code Online (Sandbox Code Playgroud)

也不要使用print,只是说明footballdisplay(football)在笔记本电池的最后一行.