UPDATED BY
Brennan Whitfield | Feb 23, 2024

In this story, I’m going to explain how to display all of the columns and rows of a Pandas DataFrame. I’ll also explain how to show all values in a list inside a DataFrame and choose the precision of the numbers in a DataFrame. And you can do it all with the same tool.

5 Steps to Display All Columns and Rows in Pandas

  1. Go to options configuration in Pandas.
  2. Display all columns with: “display.max_columns.”
  3. Set max column width with: “max_columns.”
  4. Change the number of rows with: “max_rows” and “min_rows.”
  5. Set the sequence of items with: “max_seq_items.”

I’ll be using the top 250 IMDB movies dataset, downloaded from Data World. The database has 250 rows and 37 columns.

RelatedHow to Convert a Dictionary Into a Pandas DataFrame

 

The Problem: Pandas Truncates Information

Sometimes you may read a DataFrame with a lot of rows or columns, but when you display it in Jupyter, the rows and columns are hidden (highlighted in the red boxes):

movies = pd.read_csv("data/IMDB_Top250movies2_OMDB_Detailed.csv")
movies
Some rows and columns are hidden (red boxes).
Some rows and columns are hidden (red boxes). | Screenshot: Andryw Marques

They’re typically hidden to avoid displaying too much information. But sometimes you may want to see all the columns and rows. So, how do we print them all?

To do so, we need to play with the options parameters in Pandas. Let’s see.

RelatedFrom Clipboard to DataFrame With Pandas: A Quick Guide

 

How to Show All Columns and Rows in Pandas

I’ll now go over the different commands you can use to manipulate how many columns and rows you can see in Pandas, including:

  • display.max_columns
  • max_colwidth
  • max_rows and min_rows
  • max_seq_items  

 

Select Your Option

Pandas has an options configuration menu, which allows you to change the display settings of your DataFrame (and more).

All you need to do is select your option with a string name, and get/set/reset the values of it. Those functions accept a regex pattern, so if you pass a substring, it will work, unless more than one option is matched

RelatedSorting Data Frames in Pandas: A Hands-On Guide

 

Display Columns

The display.max_columns option controls the number of columns to be printed. It receives an int or None, the latter used to print all the columns):

pd.set_option('display.max_columns', None)
movies.head()
The columns are not hidden anymore. Jupyter creates a scroll bar.
The columns are not hidden anymore. Jupyter creates a scroll bar. | Screenshot: Andryw Marques

You can also use the string max_columns instead of display.max_columns. Remember that it accepts a regex:

pd.set_option('max_columns', None)

To pass a number instead of “None,” enter:

pd.set_option('max_columns', 2)
movies.head()
Showing only 2 columns.
Showing only 2 columns. | Screenshot: Andryw Marques

To go back to the default value, you need to reset the option:

pd.reset_option(“max_columns”)
movies.head()
Some columns are hidden again.
Some columns are hidden again. | Screenshot: Andryw Marques

 

Set the Column Width

You can change the width of the column with the option max_colwidth. For example, the “plot” column has many characters and the display was originally truncated:

Some text of the plot column is hidden.
Some text of the plot column is hidden. | Screenshot: Andryw Marques

You can increase the width by passing an int. Or put at the max passing None:

pd.set_option(“max_colwidth”, None)
movies[[“Title”, “Plot”]].head()
The whole text of the plot column is being shown.
The whole text of the plot column is being shown. | Screenshot: Andryw Marques

Related8 Ways to Filter Pandas DataFrames

 

Change the Number of Rows

To change the number of rows you need to change the max_rows option.

pd.set_option("max_columns", 2) #Showing only two columns
pd.set_option("max_rows", None)
movies
All the rows are being shown. Jupyter collapses the cell and creates a scroll bar.
All the rows are being shown. Jupyter collapses the cell and creates a scroll bar. | Screenshot: Andryw Marques

Related to rows, there are two settings: max_rows and min_rows. When the number of rows is greater than max_rows, the DataFrame is truncated and it shows min_rows rows.

For example, let’s print the movies DataFrame again along with the default values of max_rows and min_rows:

print("Default max_rows: {} and min_rows: {}".format(
pd.get_option("max_rows"), pd.get_option("min_rows")))
movies
Printing the movies DatFrame with max_rows and min_rows.
Printing the movies DatFrame with max_rows and min_rows. | Image: Andryw Marques

Since the number of rows in the Dataframe is 250, which is more than the max_rows value 60, it shows the first and last five rows, which is the min_rows value we set at 10.

If we change min_rows to two, it will only display the first and the last rows:

pd.set_option(“min_rows”, 2)
movies
Showing only 2 rows, the first and the last.
Showing only 2 rows, the first and the last. | Screenshot: Andryw Marques

If we use the head command with a value below the max_rows value (60), all the rows are shown. For example, using head with value 20:

movies.head(20)
Showing all the 20 rows because this value is less than max_rows (60).
Showing all the 20 rows because this value is less than max_rows (60). | Screenshot: Andryw Marques

 

Set the Sequence of Items

The sequence of items (lists) will also be truncated if they have a lot of characters:

#Create "my_list" column and put a list of 100 values in each row
movies[‘my_list’] = [[1]*100] * 250 
movies.head()
Truncated sequence of items (lists.)
Truncated sequence of items (lists.) | Screenshot: Andryw Marques

The option to change this behavior is max_seq_items. But we also have to change the max_colwidth. If we change the max_colwidth, the lists will be truncated:

pd.set_option(“max_colwidth”, None)
movies.head()
“My_list” column expanded but the lists are truncated.
“My_list” column expanded but the lists are truncated. | Screenshot: Andryw Marques

So, you’ll need to change the max_seq_item.

pd.set_option(“max_seq_item”, None)
movies.head()
Showing all the values of the lists.
Showing all the values of the lists. | Screenshot: Andryw Marques
Showing all the values of the lists. | Screenshot: Andryw Marques

More on Pandas: A Guide to Pandas Pivot Table

 

Precision of Numbers in Pandas DataFrame

Another useful option is to set the float precision, or the number of places after the decimal, using the precision option.

#adding more decimal places to imdbRating column
movies[‘imdbRating’] = movies[‘imdbRating’] + 0.11111
movies[[‘imdbRating’]].head()
Numbers with 5 decimal places.
Numbers with 5 decimal places. | Screenshot: Andryw Marques
Numbers with 2 decimal places.
Numbers with 2 decimal places. | Screenshot: Andryw Marques
pd.set_option(‘precision’, 2)
movies[[‘imdbRating’]].head()

 

Frequently Asked Questions

How to show all columns and rows in a Pandas DataFrame

To show all columns and rows in a Pandas DataFrame, do the following: 

  1. Go to the options configuration in Pandas.
  2. Display all columns with: “display.max_columns.”
  3. Set max column width with: “max_columns.”
  4. Change the number of rows with: “max_rows” and “min_rows.”
  5. Set the sequence of items with: “max_seq_items.”
Expert Contributors

Built In’s expert contributor network publishes thoughtful, solutions-oriented stories written by innovative tech professionals. It is the tech industry’s definitive destination for sharing compelling, first-person accounts of problem-solving on the road to innovation.

Learn More

Great Companies Need Great People. That's Where We Come In.

Recruit With Us