Visualization Options for Jupyter Notebooks

Last updated:
Table of Contents

Reasonable default options for pandas dataframes

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)

# for text columns
pd.set_option('display.max_colwidth',500)
pd.set_option('display.html.use_mathjax',False)

Show full text columns on dataframe

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 1000 looks like enough

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

Set max display columns for dataframe

use pandas.set_option('display.max_columns',1000)

Set max number of rows to display

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

Show full numpy arrays and pandas Series

threshold controls the number of elements that trigger truncation.

import numpy as np

# show 
np.set_printoptions(threshold=1000)

Show more edge items

edgeitems controls the number of elements shown when truncation is triggered

import numpy as np

# show 10 elements on either side
np.set_printoptions(edgeitems=10)

References

Dialogue & Discussion