如何在IPython pandas中配置显示输出 [英] How to configure display output in IPython pandas

查看:535
本文介绍了如何在IPython pandas中配置显示输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的OS X终端中配置我的IPython输出,但似乎我试图设置的所有更改都没有生效。我正在尝试配置显示设置,以便输出更宽的输出,如大 DataFrame ,而不会截断或作为摘要信息输出。

I'm trying to configure my IPython output in my OS X terminal, but it would seem that none of the changes I'm trying to set are taking effect. I'm trying to configure the display settings such that wider outputs like a big DataFrame will output without any truncation or as the summary info.

将pandas导入我的脚本之后,我有一些选项设置我尝试了一大堆,但任何一个(或所有,就此而言)似乎都没有生效。我正在使用%run 从IPython运行脚本。我在这里做错了吗?

After importing pandas into my script, I have a few options set where I tried a whole bunch, but any one (or all, for that matter) does not seem to take effect. I'm running the script from IPython using %run. Am I doing something wrong here?

import pandas as pd

pd.set_option('display.expand_max_repr', False)
pd.set_option('display.max_columns', 30)
pd.set_option('display.width', None)
pd.set_option('display.line_width', 200)

我看过一些线程在Stack和 pandas FAQ 无济于事,即使在display namespace(或没有)下使用它们,正如我在这里尝试的那样。

I've looked at some threads on Stack and the pandas FAQ to no avail, even when using these under the display namespace (or without), as I've attempted here.

我知道有一些解决方法,例如调用 to_string() describe()输出中的方法,但这些方法非常手动,并且在某些情况下并不总是按预期工作,例如我调用的方法 to_string() groupby 对象上产生:

I understand that there are some ways around this, such as calling to_string() or describe() methods on your output, but these are very manual, and don't always work as intended in some cases, like one where I have calling to_string() on a groupby object yields:

    id       type
106125       puzzle       gameplay_id  sitting_id  user_id           ...
106253       frames       gameplay_id  sitting_id  user_id           ...
106260       trivia       gameplay_id  sitting_id  user_id           ...

我的终端窗口大小足以容纳宽度,并且调用 pd.util.terminal.get_terminal_size()正确找到窗口大小元组,所以看起来自动检测大小也不起作用。任何见解都会受到赞赏!

My terminal window size is more than sufficient to accommodate the width, and calling pd.util.terminal.get_terminal_size() is correctly finding the window size tuple, so it would seem that auto detecting the size isn't working either. Any insight would be appreciated!

推荐答案

为了完整起见(我将我的评论添加为答案),你错过了:

Just for completeness (I'll add my comment as an answer), you missed out:

pd.options.display.max_colwidth  # default is 50

这限制了单个列的最大长度。

有相当的这里配置的选项很少,如果你使用ipython然后tab完成找到全套显示选项

There are quite a few options to configure here, if you're using ipython then tab complete to find the full set of display options:

pd.options.display.<tab>

这篇关于如何在IPython pandas中配置显示输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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