Options And Settings — Pandas 1.4.3 Documentation

Overview#

pandas has an options API configure and customize global behavior related to DataFrame display, data behavior and more.

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:

In [1]: importpandasaspd In [2]: pd.options.display.max_rows Out[2]: 15 In [3]: pd.options.display.max_rows = 999 In [4]: pd.options.display.max_rows Out[4]: 999

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

  • get_option() / set_option() - get/set the value of a single option.

  • reset_option() - reset one or more options to their default value.

  • describe_option() - print the descriptions of one or more options.

  • option_context() - execute a codeblock with a set of options that revert to prior settings after execution.

Note

Developers can check out pandas/core/config_init.py for more information.

All of the functions above accept a regexp pattern (re.search style) as an argument, to match an unambiguous substring:

In [5]: pd.get_option("display.chop_threshold") In [6]: pd.set_option("display.chop_threshold", 2) In [7]: pd.get_option("display.chop_threshold") Out[7]: 2 In [8]: pd.set_option("chop", 4) In [9]: pd.get_option("display.chop_threshold") Out[9]: 4

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

In [10]: pd.get_option("max") --------------------------------------------------------------------------- OptionErrorTraceback (most recent call last) Cell In[10], line 1 ----> 1 pd.get_option("max") File ~/work/pandas/pandas/pandas/_config/config.py:274, in CallableDynamicDoc.__call__(self, *args, **kwds) 273 def__call__(self, *args, **kwds) -> T: --> 274 return self.__func__(*args, **kwds) File ~/work/pandas/pandas/pandas/_config/config.py:146, in _get_option(pat, silent) 145 def_get_option(pat: str, silent: bool = False) -> Any: --> 146 key = _get_single_key(pat, silent) 148 # walk the nested dict 149 root, k = _get_root(key) File ~/work/pandas/pandas/pandas/_config/config.py:134, in _get_single_key(pat, silent) 132 raise OptionError(f"No such keys(s): {repr(pat)}") 133 if len(keys) > 1: --> 134 raise OptionError("Pattern matched multiple keys") 135 key = keys[0] 137 if not silent: OptionError: Pattern matched multiple keys

Warning

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

Từ khóa » Html Column Maximum Width