Reputation: 1330
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?
Upvotes: 3
Views: 2615
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