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.
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:
Method 2: pd.set_option for Display
Temporarily or permanently change how many columns pandas displays:
Context Manager (Temporary)
All Useful Display Options
Method 3: df.info()
Shows column names, dtypes, and non-null counts:
For DataFrames with more than 100 columns, info() truncates by default. Show all with:
Method 4: Print One Column Per Line
Method 5: df.dtypes
Shows column names with their data types:
Filtering Column Names
Sorting and Searching Columns
Jupyter Notebook Display
Common Pitfalls
- Confusing
df.columnswithdf.columns.tolist():df.columnsreturns anIndexobject, 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_columnsglobally without resetting:pd.set_option('display.max_columns', None)affects all subsequent output in the session. For one-time display, usepd.option_context()as a context manager to automatically restore defaults. - Using
df.info()on very large DataFrames withverbose=True: On DataFrames with thousands of columns,info(verbose=True)produces enormous output. Usedf.columns.tolist()orlen(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]ordf.reindex(columns=desired_order)to enforce a specific order. - Not accounting for MultiIndex columns: If the DataFrame has a
MultiIndexcolumn header (frompivot_tableorgroupby),df.columnsreturns tuples. Usedf.columns.get_level_values(0)to access a specific level.
Summary
df.columns.tolist()returns a plain Python list of all column namespd.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 columnsdf.select_dtypes(include=['number'])filters columns by data type
Related reading
- How to show PIL Image in ipython notebook
- How to show training and predicted values on Tensorboard using python
- How to shuffle two numpy datasets using TensorFlow 2.0?
- How to simplify Tensorboard graph with shared variables?
- How to show loss values during training in scikit-learn?
- How to show progress on aiohttp POST with both form data and file
- How to skip the headers when processing a csv file using Python?
- How to smooth a curve for a dataset
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack 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.