Is there a concise way to show all rows in pandas for just the current command?

This seems to work as expected in pandas 0.22.0 (importing only pandas, without IPython):

import pandas as pd    
with pd.option_context("display.max_rows", 1000): myDF

Presumably that's because the default behaviour is to return the repr of myDF. IDEs may well override this.

If that's too much typing, then a straightforward print to the terminal also works when wrapped in a function:

from __future__ import print_statement  # for python2

def show_rows(df, nrows=1000):
    with pd.option_context("display.max_rows", nrows): print(df)

Edit: calling show_rows(df) will by default print the first 1000 rows of your dataframe df to standard output.


This won't display anything because it does not return anything:

with pd.option_context("display.max_rows", 1000): myDF

Calling display inside the with block should work:

with pd.option_context("display.max_rows", 1000):
    display(myDF)

Tags:

Python

Pandas