gpt4 book ai didi

python - jupyter-notebook:循环打印精细表格

转载 作者:行者123 更新时间:2023-12-01 09:10:34 27 4
gpt4 key购买 nike

当我在 jupyter-notebook 中输入数据框的名称时,它会打印一个漂亮的表格:

fail_data

enter image description here

它甚至可以识别 TeX 符号。

但是当我需要打印循环中的数据时,输出看起来不太好:

fail_data_gr = fail_data.groupby('test_name')
for k, v in fail_data_gr:
print(v)

enter image description here

如何使此输出看起来像第一个输出?

最佳答案

在 jupyter 笔记本中显示委托(delegate)给 IPython.display 模块。在循环内打印时,print 转储 DataFrame 的 __str__ 表示形式,它不进行特殊渲染。

所以,总而言之,改变

for k, v in fail_data_gr:
print(v)

from IPython.display import display
for k, v in fail_data_gr:
display(v)

关于python - jupyter-notebook:循环打印精细表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51690027/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com