如何在 IPython pandas 中配置显示输出 [英] How to configure display output in 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.
在将熊猫导入我的脚本后,我设置了几个选项,我尝试了一大堆,但任何一个(或全部,就此而言)似乎都不起作用.我正在使用 %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 无济于事,即使在显示命名空间下使用这些(或不使用),正如我在这里尝试的那样.
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()
方法,但这些方法非常手动,并且不要在某些情况下,并不总是按预期工作,例如我在 groupby
对象上调用 to_string()
会产生:
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 然后选项卡完成找到 全套显示选项:
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屋!