24

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.

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)

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.

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

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!

Community
  • 1
  • 1
Chrispy
  • 1,300
  • 3
  • 11
  • 25
  • Have you considered using iPython Notebook? You can render dataframes in HTML which allows you to view untruncated versions of your data. – Woody Pride Jan 21 '14 at 04:32
  • yeah this sounds interesting, I haven't really considered it until now (I'm new to pandas). Do you know of a good resource to get it up and running? – Chrispy Jan 21 '14 at 04:43
  • 1
    Umm... gosh its been so long since I installed it. You basically install iPython and then in the command line type ipython notebook. Its an incredibly useful tool, you can write markdown, include graphs, pictures, videos, HTML, LaTex etc. Its quite remarkable. For data workflow it simply cannot be beaten in my opinion. I prepared this notebook for my organisation that shows some of what iPython can do... http://goo.gl/1Vneam Its really not hard to get up and running. – Woody Pride Jan 21 '14 at 04:51
  • turned out to be relatively easy with anaconda (comes packaged with it), so I'm up and running with notebook now. Just needed to run a few updates on conda and even got a prompt to update pip in the process ;) – Chrispy Jan 21 '14 at 05:09
  • Enjoy... I love the notebooks! – Woody Pride Jan 21 '14 at 05:11
  • When you are up and running simply `from IPython.core.display import HTML` and then `HTML(df.to_html())` – Woody Pride Jan 21 '14 at 05:13
  • @WoodyPride thanks for the primer on the notebook =) – Chrispy Jan 21 '14 at 05:27
  • 1
    @Chrispy you missed out max_colwidth ... it looks like you have a long column? – Andy Hayden Jan 21 '14 at 07:21
  • @AndyHayden I'm honestly not sure. Should it be `set_option('display.max_colwidth', 200)`? – Chrispy Jan 22 '14 at 00:54

2 Answers2

25

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:

pd.options.display.<tab>
Andy Hayden
  • 359,921
  • 101
  • 625
  • 535
  • Andy -- When try setting `display.max_colwidth=None` in `master`, I get `ValueError: Value must have type ''`. Any thoughts on how to remove this limit (in the same way `None` removes limits for other options?) – Amelio Vazquez-Reina May 01 '14 at 13:30
  • 2
    @user815423426 have you tried display.max_colwidth=0 ? – Andy Hayden May 01 '14 at 13:36
0

The solution works well for strings but not for the columns with numbers. In that case to get the correct width, the format can be changed with:

pd.set_option('display.float_format', '{:15.10f}'.format)

Also, to change the display just once and not for the whole notebook:

with pd.option_context('display.max_colwidth', None):
    print(df)  # or display(df)
rehaqds
  • 414
  • 2
  • 6