Show all columns of Pandas DataFrame
Pandas sometimes hides some columns by default if the DataFrame is too wide. To view all the columns in a DataFrame pandas provides a simple way to change the display settings using the pd.set_option() function. This function allow you to control how many rows or columns are displayed in the output.
Syntax: pd.set_option('display.max_columns', None)
By setting display.max_columns to None Pandas will show all columns in the DataFrame.
1. Displaying All Columns in a DataFrame
To limit the number of columns to display, pandas replaces middle columns with an ellipsis (...). To display all column we can use pd.set_option("display.max_columns", None). We will be using creditcard.csv
import pandas as pd
df = pd.read_csv("creditcard.csv")
pd.set_option('display.max_columns', None)
df
Output:

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:
pd.reset_option('display.max_columns')
df
Output:

2. 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
:
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')
3. Displaying All Columns by Adjusting Column Width
When working with categorical data you may face 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, here 500 means columns width. You can download dataset from here.
import pandas as pd
df = pd.read_csv('data.csv')
pd.set_option('display.max_colwidth', 500)
df
Output:
By using these methods we can see all columns of Pandas dataframe.