2.2. About Options

2.2.1. SetUp

>>> import pandas as pd
>>> df = pd.DataFrame()

2.2.2. Display Output

  • pd.set_option('display.max_columns', 50)

  • pd.set_option('display.max_rows', 200)

  • pd.set_option('display.width', 500)

Limited:

>>> pd.set_option('display.max_columns', 50)
>>> pd.set_option('display.max_rows', 200)
>>> pd.set_option('display.width', 500)

Unlimited:

>>> pd.set_option('display.max_columns', None)
>>> pd.set_option('display.max_rows', None)
>>> pd.set_option('display.width', None)

2.2.3. Using in context

  • with pd.option_context('display.max_rows', 100)

>>> with pd.option_context('display.max_rows', 100):
...     print(df)
Empty DataFrame
Columns: []
Index: []
>>> with pd.option_context('display.max_rows', 50, 'display.max_columns', 10):
...     print(df)
Empty DataFrame
Columns: []
Index: []

2.2.4. Memory Usage

  • display.memory_usage: bool, str or None

  • This specifies if the memory usage of a DataFrame should be displayed when df.info() is called.

  • Valid values True, False, 'deep'

  • Default: True

2.2.5. Precision

  • display.precision: int

  • Floating point output precision in terms of number of places after the decimal

  • For regular formatting as well as scientific notation

  • Default: 6

Floating point output precision in terms of number of places after the decimal, for regular formatting as well as scientific notation.

2.2.6. Use Case - 1

>>> try:
...     import pandas as pd
...     pd.set_option('display.max_columns', 50)
...     pd.set_option('display.max_rows', 200)
...     pd.set_option('display.width', 500)
...     pd.set_option('display.memory_usage', 'deep')
...     pd.set_option('display.precision', 4)
... except ImportError:
...     pass

2.2.7. Assignments