gpt4 book ai didi

python - pretty-print 整个 Pandas Series/DataFrame

转载 作者:行者123 更新时间:2023-12-03 20:25:59 26 4
gpt4 key购买 nike

我经常在终端上使用 Series 和 DataFrames。 Series 的默认 __repr__ 返回一个缩减样本,其中包含一些头尾值,但其余部分缺失。

是否有一种内置的方式来漂亮地打印整个 Series/DataFrame?理想情况下,它将支持正确对齐,可能是列之间的边界,甚至可能是不同列的颜色编码。

最佳答案

您还可以使用 option_context ,有一个或多个选项:

with pd.option_context('display.max_rows', None, 'display.max_columns', None):  # more options can be specified also
print(df)

这会自动将选项返回到它们之前的值。

如果您正在使用 jupyter-notebook,使用 display(df) 而不是 print(df) 将使用 jupyter 丰富的显示逻辑 (like so) .

关于python - pretty-print 整个 Pandas Series/DataFrame,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47761817/

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