Reputation: 1330
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!
Upvotes: 24
Views: 15344
Reputation: 2055
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)
Upvotes: 0
Reputation: 375745
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>
Upvotes: 25