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: