如何在 IPython pandas 中配置显示输出

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21249206/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 21:35:49  来源:igfitidea点击:

How to configure display output in IPython pandas

pythonterminalpandasipython

提问by Chrispy

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 DataFramewill output without any truncation or as the summary info.

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

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?

将大Pandas导入我的脚本后,我设置了几个选项,我尝试了一大堆,但任何一个(或全部,就此而言)似乎都不起作用。我正在使用%run. 我在这里做错了吗?

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)

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

我已经查看了 Stack上的一些线程Pandas FAQ无济于事,即使在显示命名空间(或没有)下使用这些时,我也在这里尝试过。

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 groupbyobject yields:

据我所知,有一些解决这个办法,如调用to_string()describe()在你的输出方式,但这些都是非常手册,并如预期在某些情况下,像一个在那里我有打电话并不总是工作to_string()groupby对象产生:

    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           ...

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!

我的终端窗口大小足以容纳宽度,并且调用pd.util.terminal.get_terminal_size()正确地找到了窗口大小元组,因此似乎自动检测大小也不起作用。任何见解将不胜感激!

回答by Andy Hayden

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

只是为了完整性(我将添加我的评论作为答案),您错过了:

pd.options.display.max_colwidth  # default is 50

this restricted the maximum length of a single column.

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

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:

这里有很多选项可以配置,如果你使用 ipython 然后选项卡完成找到完整的显示选项集

pd.options.display.<tab>