How to stop line breaks in output of Pandas dataframes

I am working with wide pandas dataframes.

My display is currently creating an output that only extends about 1/3 across the screen. It breaks to the next column of a wide dataframe with a ‘’.

I would like to be able to see a dataframe where its rows are all on the same row. Is there a way to prevent the line breaks and instead have a horizontal scroll bar for the output?

What have you tried? Just the default rendering?
As you are finding, with larger dataframes that is often more of a preview.
There’s several ways to customize the display on the Pandas side and you can decide if it is just for the current context or all subsequent views in cells below.

Some options demonstrated for just the current cell controlling how many max columns and rows to display and to show all the text in a column:

#based on and
with pd.option_context('display.max_rows', None, 'display.max_columns', None,'display.max_colwidth', -1):

Otherwise you can set the options for display in subsequent cells, see this post showing some examples.
Here is some example code you can adapt:

``` python

Plus, there are several other viewers / data explorers you can use in JupyterLab along with Pandas dataframes.


Thank you. The first snippet of code produces exactly what I was after. I tried changing the second snippet to:


I thought this would replicate the results of the first snippet, but it doesn’t seem to work.

The first result is nice because it DOESN’T wrap the entire dataframe, but it DOES wrap the contents of each column.

Is there a way for the second snippet to produce the same styling as the first snippet? I am not sure what you mean when you say ‘there are several other viewers / data explorers you can use’. Are you referring to extensions? Thanks again.

Those weren’t meant to correspond exactly; they just were some samples of the pd.set_option() options that I had handy. I think they were the ones in the example from the post and replies. There’s a lot of them listed here. Perhaps one of them does what you say is your preference to replace pd.set_option('display.width',-1).

Some of the viewers may be extensions. I’m not sure of the underlying mechanisms. Since you are talking JupyterLab, I know there is ipyregulartable - An ipywidgets wrapper of regular-table for Jupyter and the related Perspective that “is an interactive analytics and data visualization component, which is especially well-suited for large and/or streaming datasets.”

There several of those viewers/explorers that I think work in notebooks; however, I cannot say how well they do in JupyterLab. Some of these others are listed here and qgrid. And there is a related JupyterLab extension you can learn about from links here.

1 Like