Chrispy
Chrispy

Reputation: 1330

IPython and OS X terminal output is line wrapping before column limit

I'm using IPython working with the pandas module which allows for the DataFrame object. When I'm running some code, I get an output where the DataFrame output is wrapping before the width of my terminal despite that the terminal width should accommodate the length. This issue seems to be isolated only to the pandas Series and DataFrame objects and not say, a long list.

Running pip uninstall readline and then reinstalling readline through easy_install and restarting IPython did not solve the problem.

It would be helpful to see my data not broken up like that, but I honestly don't know where to begin to fix this. Any insight?

offending output

Upvotes: 3

Views: 2615

Answers (1)

Chrispy
Chrispy

Reputation: 1330

I found a workaround that allows the console output to be more readable. Calling to_string() on the DataFrame object returns a string representation of the object, skirting around whatever inherent formatting that DataFrame contains, especially since the goal is readability.

data = DataFrame(some_long_list)
print data.to_string() # outputs to console's full-width

EDIT: From pandas docs: "New since 0.10.0, wide DataFrames will now be printed across multiple rows by default". I'm seeing that this helps as a default so that instead of cramming rows onto the next line, you'll see separation by column. There are two additional methods to configure output width:

import pandas as pd 
pd.set_option('line_width', 40) # default is 80

or to turn off the wrap feature completely:

pd.set_option('expand_frame_repr', False)

Upvotes: 5

Related Questions