漂亮地打印整个 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.
是否有一种内置方法可以漂亮地打印整个Series/DataFrame?理想情况下,它将支持适当的对齐方式,也许支持列之间的边界,甚至可以为不同的列进行颜色编码.
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.
推荐答案
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屋!