How to Show All Rows of a Pandas DataFrame


You can force a Jupyter notebook to show all rows in a pandas DataFrame by using the following syntax:

pd.set_option('display.max_rows', None)

This tells the notebook to set no maximum on the number of rows that are shown.

The following example shows how to use this syntax in practice.

Example: Show All Rows in Pandas DataFrame

Suppose we create a pandas DataFrame with 500 rows and 3 columns.

If we attempt to display the DataFrame in a Jupyter notebook, only the first five rows and last five rows will be shown:

import pandas as pd
import numpy as np

#create dataFrame with 500 rows and 3 columns
df = pd.DataFrame(index=np.arange(500), columns=np.arange(3))

#view dataFrame
df

To display all of the rows, we can use the following syntax:

#specify that all rows should be shown
pd.set_option('display.max_rows', None)

#view DataFrame
df

The results are too long to display in a single screenshot, but the Jupyter notebook does indeed display all 500 rows.

To reset the default display settings, we can use the following syntax:

pd.reset_option('display.max_rows')

If we attempt to display the DataFrame in the Jupyter notebook, only the first five rows and last five rows will be shown once again.

Additional Resources

The following tutorials explain how to perform other common operations in pandas:

How to Show All Columns of a Pandas DataFrame
How to Save Pandas DataFrame for Later Use

Leave a Reply

Your email address will not be published.