iPython笔记本未将数据帧打印为选项卡

2024-07-08 10:57:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在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

输出

^{pr2}$

我按照建议尝试了“显示”: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打印成一个具有良好的垂直和水平线的表?在


Tags: dataframedfdatadisplayyearteambearsprint
1条回答
网友
1楼 · 发布于 2024-07-08 10:57:40

set_printoptions已被set_options替换,在较新版本的pandas中,请尝试使用:

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

也不要使用print,只需在笔记本单元格的最后一行中声明football或{}。在

相关问题 更多 >

    热门问题