有没有办法(漂亮)打印整个 pandas 系列/ DataFrame? [英] Is there a way to (pretty) print the entire Pandas Series / DataFrame?

查看:744
本文介绍了有没有办法(漂亮)打印整个 pandas 系列/ DataFrame?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在终端上使用Series和DataFrames很多。一个系列的默认 __ repr __ 返回一个被压缩的样本,其中包含一些头尾值,但其余的缺少。



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

解决方案

如果这个问题出现了很多,可以做一个像这样的功能。您甚至可以配置它每次启动IPython时加载: https:// ipython。 org / ipython-doc / 1 / config / overview.html

  def print_full(x):
pd.set_option('display.max_rows',len(x))
print(x)
pd.reset_option('display.max_rows')
/ pre>

对于着色,过于精细的颜色对我来说起反作用,但我同意像 .table-striped 将会很好。您可以随时创建问题来建议此功能。


I work with Series and DataFrames on the terminal a lot. The default __repr__ for a Series returns a reducted 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.

解决方案

Sure, if this comes up a lot, make a function like this one. You can even configure it to load every time you start IPython: https://ipython.org/ipython-doc/1/config/overview.html

def print_full(x):
    pd.set_option('display.max_rows', len(x))
    print(x)
    pd.reset_option('display.max_rows')

As for coloring, getting too elaborate with colors sounds counterproductive to me, but I agree something like bootstrap's .table-striped would be nice. You could always create an issue to suggest this feature.

这篇关于有没有办法(漂亮)打印整个 pandas 系列/ DataFrame?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆