概述

pandas has an options system that lets you customize some aspects of its behaviour, display-related options being those the user is most likely to adjust.

Options have a full “dotted-style”, case-insensitive name (e.g. display.max_rows). You can get/set options directly as attributes of the top-level options attribute:

  1. In [1]: import pandas as pd
  2. In [2]: pd.options.display.max_rows
  3. Out[2]: 15
  4. In [3]: pd.options.display.max_rows = 999
  5. In [4]: pd.options.display.max_rows
  6. Out[4]: 999

The API is composed of 5 relevant functions, available directly from the pandas namespace:

Note: Developers can check out pandas/core/config.py for more information.

All of the functions above accept a regexp pattern (re.search style) as an argument, and so passing in a substring will work - as long as it is unambiguous:

  1. In [5]: pd.get_option("display.max_rows")
  2. Out[5]: 999
  3. In [6]: pd.set_option("display.max_rows",101)
  4. In [7]: pd.get_option("display.max_rows")
  5. Out[7]: 101
  6. In [8]: pd.set_option("max_r",102)
  7. In [9]: pd.get_option("display.max_rows")
  8. Out[9]: 102

The following will not work because it matches multiple option names, e.g. display.max_colwidth, display.max_rows, display.max_columns:

  1. In [10]: try:
  2. ....: pd.get_option("column")
  3. ....: except KeyError as e:
  4. ....: print(e)
  5. ....:
  6. 'Pattern matched multiple keys'

Note: Using this form of shorthand may cause your code to break if new options with similar names are added in future versions.

You can get a list of available options and their descriptions with describe_option. When called with no argument describe_option will print out the descriptions for all available options.