You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* commit 'v0.10.0b1-65-g6cadd6c':
BUG: workaround numpy issue in 1.6.2 on certain distros
BUG: use "for" as keyword to test against
ENH: option names must valid, non-keyword python identifiers
TST: option names must valid, non-keyword python identifiers
BUG: make sure pd.options style access triggers warnings and callbacks as needed
ENH: provide attribute style access to options via pd.options
REF: rename option key "print" to "display"
BUG: use Series name attributes for colnames in concat with axis=1. closepandas-dev#2489
ENH: add max_cols as keyword in DataFrame.info pandas-dev#2524
BUG: allow users to set the max number of columns before per column info is hidden away pandas-dev#2524
BUG: DataFrame.from_dict does not work with dict of sequence and orient=index pandas-dev#2496
ENH: df.select uses bool(crit(x)) rather then crit(x)
DOC: add FAQ section on monkey-patching
BUG: diff should cast n to int pandas-dev#2523
Copy file name to clipboardExpand all lines: doc/source/basics.rst
+31-16
Original file line number
Diff line number
Diff line change
@@ -1049,34 +1049,49 @@ Working with package options
1049
1049
.. _basics.working_with_options:
1050
1050
1051
1051
Introduced in 0.10.0, pandas supports a new system for working with options.
1052
-
The 4 relavent functions are available directly from the ``pandas`` namespace,
1053
-
and they are:
1052
+
Options have a full "dotted-style", case-insensitive name (e.g. ``display.max_rows``),
1053
+
1054
+
You can get/set options directly as attributes of the top-level ``options`` attribute:
1055
+
1056
+
.. ipython:: python
1057
+
1058
+
import pandas as pd
1059
+
pd.options.display.max_rows
1060
+
pd.options.display.max_rows =999
1061
+
pd.options.display.max_rows
1062
+
1063
+
1064
+
There is also an API composed of 4 relavent functions, available directly from the ``pandas``
1065
+
namespace, and they are:
1054
1066
1055
1067
- ``get_option`` / ``set_option`` - get/set the value of a single option.
1056
1068
- ``reset_option`` - reset one or more options to their default value.
1057
1069
- ``describe_option`` - print the descriptions of one or more options.
1058
1070
1059
1071
**Note:** developers can check out pandas/core/config.py for more info.
1060
1072
1061
-
Options have a full "dotted-style", case-insensitive name (e.g. ``print.max_rows``),
1073
+
1062
1074
but all of the functions above accept a regexp pattern (``re.search`` style) as argument,
1063
1075
so passing in a substring will work - as long as it is unambiguous :
1064
1076
1065
1077
.. ipython:: python
1066
1078
1067
-
get_option("print.max_rows")
1068
-
set_option("print.max_rows",101)
1069
-
get_option("print.max_rows")
1079
+
get_option("display.max_rows")
1080
+
set_option("display.max_rows",101)
1081
+
get_option("display.max_rows")
1070
1082
set_option("max_r",102)
1071
-
get_option("print.max_rows")
1083
+
get_option("display.max_rows")
1072
1084
1073
1085
1074
-
However, the following will **not work** because it matches multiple option names, e.g.``print.max_colwidth``, ``print.max_rows``, ``print.max_columns``:
1086
+
However, the following will **not work** because it matches multiple option names, e.g.``display.max_colwidth``, ``display.max_rows``, ``display.max_columns``:
1075
1087
1076
1088
.. ipython:: python
1077
1089
:okexcept:
1078
1090
1079
-
get_option("print.max_")
1091
+
try:
1092
+
get_option("display.max_")
1093
+
exceptKeyErroras e:
1094
+
print(e)
1080
1095
1081
1096
1082
1097
**Note:** Using this form of convenient shorthand may make your code break if new options with similar names are added in future versions.
@@ -1103,23 +1118,23 @@ All options also have a default value, and you can use the ``reset_option`` to d
Pandas is a powerful tool and already has a plethora of data manipulation
30
+
operations implemented, most of them are very fast as well.
31
+
It's very possible however that certain functionality that would make your
32
+
life easier is missing. In that case you have several options:
33
+
34
+
1) Open an issue on `Github <https://github.com/pydata/pandas/issues/>`_ , explain your need and the sort of functionality you would like to see implemented.
35
+
2) Fork the repo, Implement the functionality yourself and open a PR
36
+
on Github.
37
+
3) Write a method that performs the operation you are interested in and
38
+
Monkey-patch the pandas class as part of your IPython profile startup
39
+
or PYTHONSTARTUP file.
40
+
41
+
For example, here is an example of adding an ``just_foo_cols()``
42
+
method to the dataframe class:
43
+
44
+
.. ipython:: python
45
+
46
+
import pandas as pd
47
+
defjust_foo_cols(self):
48
+
"""Get a list of column names containing the string 'foo'
49
+
50
+
"""
51
+
return [x for x inself.columns if'foo'in x]
52
+
53
+
pd.DataFrame.just_foo_cols = just_foo_cols # monkey-patch the DataFrame class
0 commit comments