How to display all Pandas dataframe column names in Jupyter ?

Today we’ll learn about how to be able to show all column names on your Pandas DataFrame when displaying it in Jupyter Notebook or Lab.

Find the default number of columns shown by Jupyter

By default, Jupyter Notebook and other Python IDEs (such as PyCharm) display up to 20 columns. This is governed by the Pandas option display.max_columns.

You can easily show the default number of DataFrame columns which your Python IDE will display by using the following code

import pandas as pd

# The result will be:


Display all DataFrame columns in Jupyter

To extend the number of Pandas DataFrame columns displayed in Jupyter, type the code below:

pd.set_option('display.max_columns', <your_df_numbers_of_columns>)

Replace the <number_of_columns> parameter with an integer value as needed.

Here is an example:

#Displays 40 columns
pd.set_option('display.max_columns', 40)

Using pandas display.max_columns example

Define example DataFrame

import pandas as pd
import numpy as np

n = 100
cols = 25

#create test data
salaries = np.random.normal(120,12,n).round()
week = pd.date_range('2021-01-10', periods = n, freq = 'w')

hr = dict(week = week, avg_salary=salaries)
hr_df = pd.DataFrame(hr)

# create 25 additional columns
for i in range(1,cols,1):
    hr_df['Avg_'+ str(i)] = hr_df['avg_salary']/int(i)

#display the df

Here’s our DataFrame, note that the column headers rows is truncated by default as we are exceeding the default number of shown columns.

Showing all columns

As shown beforehand we can now go ahead and set the max displayed columns in Pandas:


# or alternatively for our case


Here’s the result, note that depending on your screen resolution you might need to use the scrollbar to view all data columns.