pandas
dataframe
python
data analysis
programming tips

How to show all columns' names on a large pandas dataframe?

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

Introduction

When a pandas DataFrame has many columns, print(df) truncates the display with .... To show all column names, use df.columns.tolist() for a clean list, or set pd.set_option('display.max_columns', None) to disable truncation globally. Other approaches include df.info() for column names with dtypes, df.dtypes for a name-dtype mapping, and df.describe().columns for numeric column names.

Method 1: df.columns.tolist()

Returns a clean Python list of all column names:

python
1import pandas as pd
2import numpy as np
3
4# Create a wide DataFrame
5df = pd.DataFrame(np.random.rand(5, 50),
6                  columns=[f"feature_{i}" for i in range(50)])
7
8# Get all column names as a list
9print(df.columns.tolist())
10# ['feature_0', 'feature_1', 'feature_2', ..., 'feature_49']
11
12# Number of columns
13print(len(df.columns))  # 50

Method 2: pd.set_option for Display

Temporarily or permanently change how many columns pandas displays:

python
1# Show all columns when printing the DataFrame
2pd.set_option('display.max_columns', None)
3print(df)  # Shows all 50 columns
4
5# Reset to default
6pd.reset_option('display.max_columns')

Context Manager (Temporary)

python
1# Only affects code inside the with block
2with pd.option_context('display.max_columns', None,
3                       'display.width', None):
4    print(df)
5
6# Back to default after the block

All Useful Display Options

python
1pd.set_option('display.max_columns', None)    # Show all columns
2pd.set_option('display.max_rows', None)        # Show all rows
3pd.set_option('display.max_colwidth', None)    # Full column content
4pd.set_option('display.width', None)           # Auto-detect terminal width
5pd.set_option('display.expand_frame_repr', False)  # No line wrapping

Method 3: df.info()

Shows column names, dtypes, and non-null counts:

python
df.info()
 
1<class 'pandas.core.frame.DataFrame'>
2RangeIndex: 5 entries, 0 to 4
3Data columns (total 50 columns):
4 #   Column      Non-Null Count  Dtype
5---  ------      --------------  -----
6 0   feature_0   5 non-null      float64
7 1   feature_1   5 non-null      float64
8...
9 49  feature_49  5 non-null      float64
10dtypes: float64(50)
11memory usage: 2.0 KB

For DataFrames with more than 100 columns, info() truncates by default. Show all with:

python
df.info(verbose=True, show_counts=True)

Method 4: Print One Column Per Line

python
1# Simple loop
2for col in df.columns:
3    print(col)
4
5# With index numbers
6for i, col in enumerate(df.columns):
7    print(f"{i:3d}: {col}")
8
9# 0: feature_0
10# 1: feature_1
11# ...
12# 49: feature_49

Method 5: df.dtypes

Shows column names with their data types:

python
1print(df.dtypes)
2# feature_0     float64
3# feature_1     float64
4# ...
5# feature_49    float64
6# dtype: object
7
8# Show all without truncation
9pd.set_option('display.max_rows', None)
10print(df.dtypes)
11pd.reset_option('display.max_rows')

Filtering Column Names

python
1# Columns containing a substring
2matching = [col for col in df.columns if 'price' in col.lower()]
3print(matching)
4
5# Columns by dtype
6numeric_cols = df.select_dtypes(include=['number']).columns.tolist()
7string_cols = df.select_dtypes(include=['object']).columns.tolist()
8datetime_cols = df.select_dtypes(include=['datetime']).columns.tolist()
9
10print(f"Numeric: {len(numeric_cols)}")
11print(f"String: {len(string_cols)}")
12
13# Columns matching a regex
14import re
15pattern = re.compile(r'feature_[0-9]+')
16matching = [col for col in df.columns if pattern.match(col)]

Sorting and Searching Columns

python
1# Alphabetically sorted
2print(sorted(df.columns))
3
4# Search for a column
5search = 'feature_25'
6if search in df.columns:
7    print(f"Found '{search}' at index {df.columns.get_loc(search)}")
8
9# Columns as a DataFrame for easier inspection
10col_info = pd.DataFrame({
11    'column': df.columns,
12    'dtype': df.dtypes.values,
13    'non_null': df.count().values,
14    'unique': [df[col].nunique() for col in df.columns]
15})
16print(col_info)

Jupyter Notebook Display

python
1# In Jupyter, use display() for better formatting
2from IPython.display import display
3
4# Show all columns in Jupyter
5pd.set_option('display.max_columns', None)
6display(df.head())
7
8# Or transpose for wide DataFrames
9display(df.head().T)  # Columns become rows — easier to read

Common Pitfalls

  • Confusing df.columns with df.columns.tolist(): df.columns returns an Index object, not a plain list. Some operations that expect a list (like JSON serialization) may need .tolist(). For printing, both work, but .tolist() gives a cleaner output.
  • Setting max_columns globally without resetting: pd.set_option('display.max_columns', None) affects all subsequent output in the session. For one-time display, use pd.option_context() as a context manager to automatically restore defaults.
  • Using df.info() on very large DataFrames with verbose=True: On DataFrames with thousands of columns, info(verbose=True) produces enormous output. Use df.columns.tolist() or len(df.columns) for a quick count instead.
  • Assuming column order is stable across operations: Some pandas operations (merge, pivot, groupby) may reorder columns. If column order matters, use df = df[sorted_columns] or df.reindex(columns=desired_order) to enforce a specific order.
  • Not accounting for MultiIndex columns: If the DataFrame has a MultiIndex column header (from pivot_table or groupby), df.columns returns tuples. Use df.columns.get_level_values(0) to access a specific level.

Summary

  • df.columns.tolist() returns a plain Python list of all column names
  • pd.set_option('display.max_columns', None) disables column truncation when printing
  • Use pd.option_context() for temporary display settings that auto-reset
  • df.info(verbose=True) shows names, dtypes, and null counts for all columns
  • df.select_dtypes(include=['number']) filters columns by data type

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

All Rights Reserved.