漂亮地打印整个 Pandas 系列/DataFrame [英] Pretty-print an entire Pandas Series / DataFrame
问题描述
我经常在终端上使用 Series 和 DataFrames.系列的默认 __repr__
返回一个减少的样本,具有一些头部和尾部值,但其余的缺失.
I work with Series and DataFrames on the terminal a lot. The default __repr__
for a Series returns a reduced sample, with some head and tail values, but the rest missing.
是否有内置的方法可以漂亮地打印整个系列/数据帧?理想情况下,它会支持正确对齐,可能支持列之间的边界,甚至可能支持不同列的颜色编码.
Is there a builtin way to pretty-print the entire Series / DataFrame? Ideally, it would support proper alignment, perhaps borders between columns, and maybe even color-coding for the different columns.
推荐答案
您也可以使用 option_context
,带有一个或多个选项:
You can also use the option_context
, with one or more options:
with pd.option_context('display.max_rows', None, 'display.max_columns', None): # more options can be specified also
print(df)
这将自动将选项恢复为以前的值.
This will automatically return the options to their previous values.
如果您正在使用 jupyter-notebook,使用 display(df)
而不是 print(df)
将使用 jupyter 丰富的显示逻辑 (像这样).
If you are working on jupyter-notebook, using display(df)
instead of print(df)
will use jupyter rich display logic (like so).
这篇关于漂亮地打印整个 Pandas 系列/DataFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!