ZetCode

Pandas Display Options

last modified November 17, 2026 Python 3.15

Pandas controls how much of a table to show and how to print it through a set of global options. When a DataFrame is very large, the default representation truncates it so that the terminal or notebook is not flooded with thousands of lines. This article explains how to inspect and change those display limits.

This is different from the topic of formatting columns, which changes the values themselves, for example turning numbers into currency strings. Here we leave the data untouched and only decide how much of it is printed and in what layout. The examples were verified with Pandas 3.1.1; default option values can differ in other environments.

Getting and setting options

The pd.get_option function reads an option by its dotted name and pd.set_option changes it. The names used in this article all start with display.. A setting stays in effect for the rest of the Python process unless it is changed again.

options_getset.py
import pandas as pd

print('max_rows:', pd.get_option('display.max_rows'))
print('max_columns:', pd.get_option('display.max_columns'))
print('width:', pd.get_option('display.width'))

pd.set_option('display.max_columns', 5)
print('after set:', pd.get_option('display.max_columns'))

In this environment the defaults are 60 rows, a max_columns value of 0 (which means auto-detect the terminal width), and a width of 80 characters. After set_option, the display.max_columns value is 5. Your defaults may differ, especially inside a notebook, so it is a good idea to read them with get_option rather than assume them.

$ python options_getset.py
max_rows: 60
max_columns: 0
width: 80
after set: 5

Limiting the number of rows

The display.max_rows option sets the maximum number of rows shown when a DataFrame is printed. If the table is longer, Pandas shows a few rows at the top and bottom, with a .. marker for the skipped part and a summary line giving the full dimensions.

options_maxrows.py
import pandas as pd

df = pd.DataFrame({'n': range(15)})

print('default:')
print(df)
print()

pd.set_option('display.max_rows', 5)
print('max_rows = 5:')
print(df)

With the default limit of 60, all fifteen rows are printed. After setting the limit to five, only the first two and the last two rows appear. The line [15 rows x 1 columns] reminds us that the underlying DataFrame has not lost any data; only the representation is shorter. Setting the option to None removes the limit entirely.

$ python options_maxrows.py
default:
     n
0    0
1    1
2    2
3    3
4    4
5    5
6    6
7    7
8    8
9    9
10  10
11  11
12  12
13  13
14  14

max_rows = 5:
     n
0    0
1    1
..  ..
13  13
14  14

[15 rows x 1 columns]

Limiting the number of columns

The display.max_columns option works the same way for columns. When a table is wider than the limit, Pandas keeps a few columns on each side and inserts an ellipsis in the middle. This makes a very wide table readable without printing hundreds of columns.

options_maxcols.py
import pandas as pd

df = pd.DataFrame({f'col{i}': [i] for i in range(10)})

print('default (all columns):')
print(df)
print()

pd.set_option('display.max_columns', 4)
print('max_columns = 4:')
print(df)

The DataFrame has ten columns. With the automatic default all ten are shown; after setting the limit to four, Pandas prints two columns on the left and two on the right with ... between them. As with rows, a summary line reports the real size of the table.

$ python options_maxcols.py
default (all columns):
   col0  col1  col2  col3  col4  col5  col6  col7  col8  col9
0     0     1     2     3     4     5     6     7     8     9

max_columns = 4:
   col0  col1  ...  col8  col9
0     0     1  ...     8     9

[1 rows x 10 columns]

Setting the display width

The display.width option gives the number of characters per line. When a table is wider than that and all its columns are allowed, the representation is split into several blocks of columns placed one after another. This affects the interactive representation, which we get explicitly with repr.

options_width.py
import pandas as pd

pd.set_option('display.max_columns', None)
df = pd.DataFrame({f'col{i}': [i] for i in range(9)})

pd.set_option('display.width', 30)
print('width = 30:')
print(repr(df))
print()

pd.set_option('display.width', 200)
print('width = 200:')
print(repr(df))

We first set display.max_columns to None so that no columns are hidden. With a width of 30 characters, the nine columns are broken into three blocks, each ending with a backslash. With a width of 200 they all fit on one line. Note that print(df) does not wrap in this way because it uses the plain text form; the width option applies to the representation used by the interactive interpreter.

$ python options_width.py
width = 30:
   col0  col1  col2  col3  \
0     0     1     2     3

   col4  col5  col6  col7  \
0     4     5     6     7

   col8
0     8

width = 200:
   col0  col1  col2  col3  col4  col5  col6  col7  col8
0     0     1     2     3     4     5     6     7     8

Formatting floating-point values

The display.float_format option accepts a function that turns each floating-point number into a string, and it is applied only when the DataFrame is displayed. A common choice is a format string's format method, which gives control over decimals and thousands separators. The stored numbers are unchanged.

options_float.py
import pandas as pd

df = pd.DataFrame({'value': [1234.5678, 0.5, 98.76543]})

print('default:')
print(df)
print()

pd.set_option('display.float_format', '{:,.2f}'.format)
print('float_format:')
print(df)

By default Pandas shows up to five decimal places. With '{:,.2f}'.format each number is printed with two decimal places and a comma as the thousands separator, so 1234.5678 appears as 1,234.57. This option changes only the printed form; the values used in calculations keep their full precision.

$ python options_float.py
default:
        value
0  1234.56780
1     0.50000
2    98.76543

float_format:
     value
0 1,234.57
1     0.50
2    98.77

Temporary settings with option_context

Changing an option with set_option affects the rest of the program. When a setting is needed only for one block of code, the option_context context manager applies it temporarily and restores the previous value on exit. This keeps unrelated output unaffected.

options_context.py
import pandas as pd

df = pd.DataFrame({'n': range(10)})

print('before:')
print(df)
print()

with pd.option_context('display.max_rows', 3):
    print('inside context:')
    print(df)

print()
print('after context:')
print(df)

Inside the with block the ten-row DataFrame is truncated to three rows, while the prints before and after the block show all ten rows. The option_context function accepts several option/value pairs at once, which makes it a clean way to change the layout for a single report.

$ python options_context.py
before:
   n
0  0
1  1
2  2
3  3
4  4
5  5
6  6
7  7
8  8
9  9

inside context:
    n
0   0
.. ..
9   9

[10 rows x 1 columns]

after context:
   n
0  0
1  1
2  2
3  3
4  4
5  5
6  6
7  7
8  8
9  9

Printing the whole DataFrame with to_string

When a representation is truncated, the to_string method gives us the full text regardless of the row and column display limits. It is useful for logging or for writing a complete table into a plain-text file.

options_tostring.py
import pandas as pd

pd.set_option('display.max_rows', 4)
df = pd.DataFrame({'n': range(20)})

print('truncated print:')
print(df)
print()

print('to_string:')
print(df.to_string())

Although display.max_rows is set to four, df.to_string() lists all twenty rows. The method also accepts options of its own, such as line_width and max_rows, for fine control over a particular output. It does not modify the global display options.

$ python options_tostring.py
truncated print:
     n
0    0
1    1
..  ..
18  18
19  19

[20 rows x 1 columns]

to_string:
     n
0    0
1    1
2    2
3    3
4    4
5    5
6    6
7    7
8    8
9    9
10  10
11  11
12  12
13  13
14  14
15  15
16  16
17  17
18  18
19  19

Source

Pandas user guide - Options and settings
Pandas documentation - get_option
Pandas documentation - set_option
Pandas documentation - option_context
Pandas documentation - to_string

In this article we have read and changed Pandas display options with get_option and set_option, limited rows and columns, controlled the line width, formatted floating-point values, applied temporary settings with option_context, and printed a complete table with to_string. See also the formatting columns article for changing the values themselves and the Pandas DataFrame article for the tables being displayed.

Author

I am Jan Bodnar, a programmer and technical writer. I have been writing programming tutorials at ZetCode since 2007 and have published eight e-books. See about the author.

List all Pandas tutorials.