Pandas Display Options: Examples and Reference

Pandas Display Options: Examples and Reference

Last updated:
Table of Contents

Updated for pandas 2.x

Reasonable defaults

You can add this to the beginning of every notebook you write automatically: Add commands to the beginning of every notebook

import pandas as pd

# general options
pd.set_option('display.max_columns',100)
pd.set_option('display.max_rows',100)
pd.set_option("display.precision", 3)

# for text columns
pd.set_option('display.max_colwidth',500)
# normal text often gets parsed as mathjax by mistake
pd.set_option('display.html.use_mathjax',False)

Maximum text length

use pandas.set_option('display.max_colwidth',1000):

Say you have a column named 'synopsis' with text data:

before-set-option the default value for this setting is 50
  
after-set-option After setting max_max_colwidth
to 1000

Disable scientific notation

Use pandas.set_option('display.float_format', lambda x: '<fmtstring>' % x)

Example: use '%8.2f' as formatting:

import pandas as pd
pd.set_option('display.float_format', lambda x: '%8.2f' % x)

pd.DataFrame({
    "num":[0.0001, 10000000,100,0.5],
    "str":["foo","bar","baz","quux"]
})

before-with-default-options BEFORE: default options
         
after-with-custom-options AFTER setting display.float_format

Thousands separator

To use commas (',') as thousands separator for floats and integers:

  • Use pandas.set_option('display.float_format', lambda x: '{:,.0f}' % x) to use comma separators and no decimal places

  • Use pandas.set_option('display.float_format', lambda x: '{:,.2f}' % x) to use comma separators and 2 decimal places

import pandas as pd
pd.set_option('display.float_format', lambda x: '{:,.2f}'.format(x))

pd.DataFrame({
    "num":[100000, 100,100,200.50],
    "str":["foo","bar","baz","quux"]
})

before-no-thousands-separator BEFORE: default display options
  
after-thousands-separator-and-decimal-places AFTER: using commas as thousands
separator and 2 decimal places

Force display dataframe

Use display from IPython.display to pretty-print a dataframe even when it's not the last thing in a cell.

from IPython.display import display

display(df)

sample-printed-dataframe You can manually force print a dataframe even when
it's in the middle of the notebook cell

Max dataframe columns

Use pandas.set_option('display.max_columns', num)

Example: show up to 100 columns: pandas.set_option('display.max_columns',100)

Max dataframe rows

Use pandas.set_option('display.max_rows', num)

Example: show up to 100 rows: pandas.set_option('display.max_rows',100)

Disable math symbols

Use pandas.set_option('display.html.use_mathjax',False) to disable MathJax (Latex-style) rendering on dataframe cells.

Decimal places for floats

To set the number of decimal places for floating point numbers, set the precision:

Example: display 3 decimal places for float numbers

pandas.set_option("display.precision", 3)

Reset all options

Use pandas.reset_option("all") to reset all display options.

Reset single display option

Use pandas.reset_option("<option name>").

Example: pandas.reset_option('display.max_colwidth') to reset 'display.max_colwidth' to its default value