The Wayback Machine - https://web.archive.org/web/20250130100227/https://www.geeksforgeeks.org/show-all-columns-of-pandas-dataframe-in-jupyter-notebook/
Open In App

Show all columns of Pandas DataFrame

Last Updated : 02 Dec, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

In this article, you’ll learn how to display all columns in a Pandas DataFrame within a Jupyter Notebook using Python.

Display all Columns and Rows using set_option()

By default, Pandas limits the display for performance, but you can customize this with pd.set_option() method to enhance visibility. This function allows you to control how many rows or columns are displayed in the output.

Syntax: pd.set_option(‘display.max_columns’, None)

Parameters:

  • pat: A regex pattern matching a single option.
  • Returns: The current value of the specified option.

By setting display.max_columns to None, Pandas will show all columns in the DataFrame.

Example: Display All Columns in a DataFrame using creditcard.csv

Python
import pandas as pd 
df = pd.read_csv("creditcard.csv")

# set the max columns to none
pd.set_option('display.max_columns', None)
df 

Output:

Display-all-columns-of-Pandas-DataFrame-in-Jupyter-Notebook

The dataset contains 31 columns and all the columns are displayed using pd.set_option() method

If you no longer need to display all columns and want to revert the display settings to the default behavior pd.reset_option() method is used:


Python
import pandas as pd 
df = pd.read_csv("data.csv")

# set the max columns to none
pd.reset_option('display.max_columns')
df 

Output:

output-with-reset-option-function

Manually Listing All Column Names of Pandas DataFrame

If you only need to inspect the column names without displaying the entire DataFrame, you can list all the columns using df.columns:

Python
# Print all column names
print(df.columns)

Output:

Index(['Time', 'V1', 'V2', 'V3', 'V4', 'V5', 'V6', 'V7', 'V8', 'V9', 'V10',
'V11', 'V12', 'V13', 'V14', 'V15', 'V16', 'V17', 'V18', 'V19', 'V20',
'V21', 'V22', 'V23', 'V24', 'V25', 'V26', 'V27', 'V28', 'Amount',
'Class'],
dtype='object')

Displaying All Columns by Adjusting Column Width

When working with categorical data, you may encounter an issue where the data in the columns is not fully visible due to the default maximum column width. To fix this, we can increase the column width using pd.set_option(‘display.max_colwidth’, 500). This will ensure that all values in the DataFrame columns are fully displayed. (Dataset Link)

Python
#import pandas
import pandas as pd

# read csv
df = pd.read_csv('longer_data.csv')

# Set maximum column width to 500
pd.set_option('display.max_colwidth', 500)
df

Output:

Displaying-All-Columns-by-Adjusting-Column-Width

Displaying All Columns by Adjusting Column Width

Displaying All Columns by Setting display.max_columns to None

By default, pandas limits the number of columns it displays, replacing the middle columns with an ellipsis (…). If you’re working with a DataFrame that has many columns, you can use pd.set_option(“display.max_columns”, None) to display all columns.

Python
import pandas as pd

# Load the dataset
df = pd.read_csv('longer_data.csv')

# Set the display option to show all columns
pd.set_option("display.max_columns", None)

# Print the DataFrame to display all columns
df

Output:

Display-All-Columns-using-set-option-as-none

Displaying All Columns by Setting display.max_columns to None

By setting display.max_columns to None, pandas will display all the columns without any truncation.



Next Article
Practice Tags :

Similar Reads

three90RightbarBannerImg