Monday, September 1, 2025
HomeLanguagesHow to Show All Columns of a Pandas DataFrame?

How to Show All Columns of a Pandas DataFrame?

In this article, we will discuss how to Show All Columns of a Pandas DataFrame.

Using set_option() method

We will use the pandas set_option() method. This method will set the specified option’s value.

Syntax :

 pandas.set_option(pat, value)

Parameters :

  • pat : Regexp which should match a single option.
  • value : New value of option.

Returns :

 None

Raises

if no other option exists, the OptionError is raised

To view and download the CSV file used in the below example click train.csv.

Example:

Without using the set_option() method: 

Python3




# importing packages
import pandas as pd
  
# importing 'train.csv'
data = pd.read_csv('train.csv')
data.head()


Output:

Example:

After using the set_option() method:

Here we have given ‘display.max_columns’ as an argument to view the maximum columns from our dataframe.

Python3




# importing packages
import pandas as pd
  
# importing 'train.csv'
data = pd.read_csv('train.csv')
  
pd.set_option('display.max_columns', None)
data.head()


Output:

We can view all columns, as we scroll to the right, unlike when we didn’t use the set_option() method. If we only want to view a certain number of columns:

Syntax:

pd.set_option(‘display.max_columns’, n)

where, n is an integer.

Example:

Python3




# importing packages
import pandas as pd
  
# importing 'train.csv'
data = pd.read_csv('train.csv')
pd.set_option('display.max_columns', 4)
data.head()


Output:

RELATED ARTICLES

Most Popular

Dominic
32251 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6619 POSTS0 COMMENTS
Nicole Veronica
11792 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11841 POSTS0 COMMENTS
Shaida Kate Naidoo
6735 POSTS0 COMMENTS
Ted Musemwa
7016 POSTS0 COMMENTS
Thapelo Manthata
6689 POSTS0 COMMENTS
Umr Jansen
6707 POSTS0 COMMENTS