问题描述
我在终端上使用Series和DataFrames很多。一个系列的默认 __ repr __
返回一个被压缩的样本,其中包含一些头尾值,但其余的缺少。 是否有内置的方式漂亮打印整个系列/ DataFrame?理想情况下,它将支持正确的对齐,也许是列之间的边界,甚至可能对不同的列进行颜色编码。
如果这个问题出现了很多,可以做一个像这样的功能。您甚至可以配置它每次启动IPython时加载:
def print_full(x):
/ pre>
pd.set_option('display.max_rows',len(x))
print(x)
pd.reset_option('display.max_rows')
对于着色,过于精细的颜色对我来说起反作用,但我同意像将会很好。您可以随时来建议此功能。
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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!