Skip to main content
v2026.11,986 entries · CC-BY 4.0

pandas Display All Columns: set_option, option_context and to_string

Show every DataFrame column in pandas with set_option, option_context or to_string, and fix columns that still wrap or truncate.

Written and maintained by CASRAI Editorial Board

Published

On this page

To display all columns of a pandas DataFrame, set the display option to unlimited with pd.set_option('display.max_columns', None), or scope the change to one block with pd.option_context('display.max_columns', None), or print the frame with df.to_string(), which ignores the column limit altogether. According to the pandas options documentation, a value of None for these limits means unlimited, and if the column limit is exceeded pandas switches to a truncated view. On wide research tables, such as survey exports with dozens of items, the output may still wrap across several blocks after you do this; that is controlled by a different option, display.width, covered below.

What pandas display options are used for in research

pandas is a Python library for data analysis; its PyPI page describes it as providing “powerful data structures for data analysis, time series, and statistics”. In research workflows, DataFrames hold survey responses, instrument exports, trial datasets and coded qualitative data, and these often have dozens or hundreds of columns. When you print such a frame in a terminal, script log or notebook, pandas shows only the first and last few columns and replaces the middle with an ellipsis (...) together with a shape line such as [3 rows x 31 columns].

That truncation protects your screen, but it is a risk when you are checking a dataset: a misnamed variable, a duplicated column or an unexpected encoding in a hidden middle column cannot be seen if it is never printed. Display settings change only how a frame is shown. They never delete, reorder or alter the data, so they are safe to use during data cleaning and when you want to document a variable list for a data management plan or codebook.

How to install or access pandas

The pandas installation page gives two supported routes. With pip, from PyPI: pip install pandas. With conda, from the conda-forge channel: conda install -c conda-forge pandas. To create a fresh conda environment with pandas, the same page shows conda create -c conda-forge -n name_of_my_env python pandas followed by conda activate name_of_my_env. Optional dependencies such as Excel support are installed with pip install "pandas[excel]". The PyPI page and the pandas documentation both list version 3.1.1 as current; the examples on this page were run on that version. If you work in notebooks, see the guide on Anaconda for Jupyter Notebook.

How to display all columns in pandas step by step

The following steps use a 100-row, 31-column table of simulated Likert-scale survey responses. The data are generated randomly for illustration (an illustrative composite, not real study data): one respondent_id column and thirty item columns named q01_item to q30_item.

  1. Build or load the frame. For example import pandas as pd then df = pd.read_csv('survey.csv'). If you need to construct a frame by hand, see creating a DataFrame in Python.
  2. Check what the current limit is. Run pd.get_option('display.max_columns'). In a plain Python script on pandas 3.1.1 this returned 0. The pandas options documentation describes display.max_columns as being 0 in a terminal, where pandas auto-detects the available width, and None as unlimited.
  3. Print the frame before any change. print(df.head(3)) showed respondent_id q01_item q02_item ... q28_item q29_item q30_item followed by [3 rows x 31 columns]: the middle columns are hidden behind the ellipsis.
  4. Lift the column limit globally. Run pd.set_option('display.max_columns', None). The change lasts until you reset it or the Python process ends. Printing again shows all 31 columns.
  5. Or lift it only for one block. Use the context manager: with pd.option_context('display.max_columns', None): print(df.head(3)). The pandas documentation states that option_context executes a code block with a set of options that revert to the prior settings after execution. After the block, pd.get_option('display.max_columns') returned 0 again in our test.
  6. Or avoid global state entirely. print(df.head(3).to_string()) returns every column as a string. DataFrame.to_string also accepts max_cols to cap the number of columns, columns to choose a subset and line_width to set the wrap width.
  7. Restore defaults when finished. pd.reset_option('^display') resets every option whose name matches the pattern, which the documentation uses as its example for resetting all display options. To reset a single option, pass its full name, for example pd.reset_option('display.max_columns').

All of these calls take effect on how a frame is printed, so run them before the print or display statement that you want to change. For related column-level tasks, such as removing columns you no longer want to see, read how to drop columns in pandas.

Setting several options at once

A common research setup is to show every column, raise the row limit and widen cells in the same call: with pd.option_context('display.max_columns', None, 'display.max_rows', 200, 'display.max_colwidth', None): print(df). The options documentation shows the same pattern, an alternating list of option name and value, for display.max_rows and display.max_columns, and notes that max_rows returns to its default (60) after the block ends.

How to read the output

When columns are hidden, the printed frame has an ellipsis column and a trailing line stating the shape, for example [3 rows x 31 columns]. The numbers in that line are the true dimensions, so you can always compare them with df.shape. Once display.max_columns is None, that ellipsis column disappears and the frame is printed in full.

A second thing you may see is a trailing backslash at the end of each line and the table continuing in another block underneath. In our run, with the column limit removed but the width left at 80, the 31 columns printed as several stacked blocks of 7 to 8 columns, each line ending in . This is not truncation: every column is present, wrapped across “pages”. The options documentation says display.expand_frame_repr (default True) controls this wrapping when the frame is wider than display.width (default 80), and that max_columns is still respected.

When both display.max_columns and display.width were set to None in a script, the first rows printed on a single very long line per row. That is useful for copying into a text file and not useful for reading on a narrow screen. Choose wrapped output for reading and a single long line only for machine handling; for a wide table you intend to share, writing to a file is usually better than printing.

The data table below lists the display options that interact, with the defaults named in the pandas documentation and the value observed in a test session.

Troubleshooting pandas display

I set max_columns to None but the columns still wrap

The wrapping comes from display.width and display.expand_frame_repr. Per the options documentation, display.width defaults to 80 and, when Python or IPython runs in a terminal, may be set to None so that pandas auto-detects the width. Setting display.expand_frame_repr to False stops the wrapped “pages” in favour of a single, wider table. Choose one: accept wrapping for narrow screens, or use df.to_string() and read the result in a text editor.

Cells end with three dots instead of the full text

That is display.max_colwidth, which defaults to 50 characters; longer text is cut with a “…” placeholder, and None means unlimited. It matters for free-text survey answers and open-ended coding fields. DataFrame.to_string has its own max_colwidth parameter.

Rows are hidden in the middle

Rows are governed separately by display.max_rows (default 60) and display.min_rows (default 10, the number shown when the frame exceeds max_rows). Setting display.max_rows to None shows every row; for a long table this can flood the screen, so prefer df.head(n) or a scoped option_context.

OptionError: Pattern matched multiple keys

pandas lets you pass a regular-expression pattern or an unambiguous substring in place of a full option name. A short pattern such as 'max' matches several options (display.max_colwidth, display.max_rows and display.max_columns) and raises an OptionError saying the pattern matched multiple keys; we reproduced this with pd.get_option('max'). The options documentation warns that the shorthand may break when new options are added, so write the full name such as display.max_columns in shared analysis code.

Settings leak into later cells or scripts

A global pd.set_option call stays in force for the rest of the session, including later notebook cells and any imported module that prints frames. Use pd.option_context in reusable code and reset with pd.reset_option when you finish.

Check the column list instead of printing the table

If you only need to confirm that variables are present and spelled correctly, list(df.columns) or df.columns.tolist() returns the names without any width or truncation issues, and df.shape returns the row and column counts. For missing values in those columns, see dropna in pandas.

Free alternatives to changing the global display option

pandas is open-source, and each of these routes uses only built-in pandas features. The table summarises where each is documented.

Approach What it does Changes global state?
pd.set_option('display.max_columns', None) Removes the column limit for every frame printed in the session Yes, until reset or the process ends
pd.option_context(...) Applies options inside a with block, then restores the earlier values No, reverts after the block
df.to_string() Returns the whole frame as a string; accepts max_cols, columns, line_width, max_colwidth No
df.to_html() Returns the frame as an HTML table; accepts columns, max_rows, max_cols No
list(df.columns) Lists the column names only No

Because the first call is global and the others are not, the scoped forms are safer in code that other people will rerun. Once your wide table is readable, further steps such as applying a function across columns with apply or adding derived variables with pandas add column are covered elsewhere on this site.

Sources

Data: pandas display options that control how many columns and cells are printed

Original compilation of the pandas display options that interact when a wide DataFrame is printed, with the default stated in the pandas Options and settings documentation and, where the option was exercised, the value observed in a test session on pandas 3.1.1.

Period covered: pandas 3.1.1.

pandas display options that control how many columns and cells are printed
OptionDocumented defaultWhat it controlsObserved in test
display.max_columns0 in a terminal (auto-detect); None = unlimitedNumber of columns printed before the truncated viewReturned 0 in a script on pandas 3.1.1
display.width80Character width of the output; None lets a terminal auto-detectLeft at 80, 31 columns wrapped into stacked blocks
display.expand_frame_reprTrueWraps a frame wider than display.width across blocksWrapped output ends each line with a backslash
display.max_colwidth50Characters shown per cell before a ... placeholder; None = unlimitedReturned 50
display.max_rows60Rows printed before truncationReturned 60
display.min_rows10Rows shown when a frame exceeds max_rowsNot tested separately
display.large_reprtruncateWhether oversized frames print truncated or as a summaryNot tested separately

Sources

Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · full access

Ask about pandas Display All Columns: set_option, option_context and to_string

Full access: large monthly usage, up to 10 source passages behind each answer, and MCP and API access for Claude Code, Codex and other CLIs. Cancel any time.

An AI assistant for research: funder rules, compliance, methods and publishing. It links the sources behind its answers and labels answers that come from a web search.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays open to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →