How to Show All Columns of a Pandas DataFrame?
Pandas limit the display of rows and columns, making it difficult to view the full data, so let's learn how to show all the columns of Pandas DataFrame.

Using pd.set_option to Show All Pandas Columns
Pandas provides a set_option() function that allows you to configure various display options, including the number of columns to display.
import pandas as pd
df = pd.read_csv('train.csv')
# Set display option to show all columns
pd.set_option('display.max_columns', None)
# Show the columns
display(df)
Output:
Using df.columns to List All Column Names
If you don't need to view the entire DataFrame but just want to know the column names, you can use the df.columns attribute. This returns an index object containing all the column names.
import pandas as pd
# Read the CSV file into a DataFrame
df = pd.read_csv('train.csv')
# Print all column names
print(df.columns)
Output:
Index(['Id', 'MSSubClass', 'MSZoning', 'LotFrontage', 'LotArea', 'Street',
'Alley', 'LotShape', 'LandContour', 'Utilities', 'LotConfig',
'LandSlope', 'Neighborhood', 'Condition1', 'Condition2', 'BldgType',
'HouseStyle', 'OverallQual', 'OverallCond', 'YearBuilt', 'YearRemodAdd',
'RoofStyle', 'RoofMatl', 'Exterior1st', 'Exterior2nd', 'MasVnrType',
'MasVnrArea', 'ExterQual', 'ExterCond', 'Foundation', 'BsmtQual',
'BsmtCond', 'BsmtExposure', 'BsmtFinType1', 'BsmtFinSF1',
'BsmtFinType2', 'BsmtFinSF2', 'BsmtUnfSF', 'TotalBsmtSF', 'Heating',
'HeatingQC', 'CentralAir', 'Electrical', '1stFlrSF', '2ndFlrSF',
'LowQualFinSF', 'GrLivArea', 'BsmtFullBath', 'BsmtHalfBath', 'FullBath',
'HalfBath', 'BedroomAbvGr', 'KitchenAbvGr', 'KitchenQual',
'TotRmsAbvGrd', 'Functional', 'Fireplaces', 'FireplaceQu', 'GarageType',
'GarageYrBlt', 'GarageFinish', 'GarageCars', 'GarageArea', 'GarageQual',
'GarageCond', 'PavedDrive', 'WoodDeckSF', 'OpenPorchSF',
'EnclosedPorch', '3SsnPorch', 'ScreenPorch', 'PoolArea', 'PoolQC',
'Fence', 'MiscFeature', 'MiscVal', 'MoSold', 'YrSold', 'SaleType',
'SaleCondition', 'SalePrice'],
dtype='object')
This method is especially useful when you're debugging or need a quick overview of the columns in the DataFrame.
Using to_string()
to Display All Columns and Rows
If you need to view the entire DataFrame, including all rows and columns, use to_string(). This method converts the DataFrame into a string representation, allowing you to view everything at once.
import pandas as pd
# Read the CSV file into a DataFrame
df = pd.read_csv('train.csv')
# Display all rows and columns
print(df.to_string())
Output:

Be cautious when using this with large datasets, as it can produce a lot of output in the console.