@@ -73,8 +73,8 @@ def cut(
73
73
Specifies the labels for the returned bins. Must be the same length as
74
74
the resulting bins. If False, returns only integer indicators of the
75
75
bins. This affects the type of the output container (see below).
76
- This argument is ignored when `bins` is an IntervalIndex. If True,
77
- raises an error.
76
+ This argument is ignored when `bins` is an IntervalIndex.
77
+ If True, raises an error. When `ordered=False`, labels must be provided .
78
78
retbins : bool, default False
79
79
Whether to return the bins or not. Useful when bins is provided
80
80
as a scalar.
@@ -86,6 +86,13 @@ def cut(
86
86
If bin edges are not unique, raise ValueError or drop non-uniques.
87
87
88
88
.. versionadded:: 0.23.0
89
+ ordered : bool, default True
90
+ Whether the labels are ordered or not. Applies to returned types
91
+ Categorical and Series (with Categorical dtype). If True,
92
+ the resulting categorical will be ordered. If False, the resulting
93
+ categorical will be unordered (labels must be provided).
94
+
95
+ .. versionadded:: 1.1.0
89
96
90
97
Returns
91
98
-------
@@ -146,6 +153,13 @@ def cut(
146
153
[bad, good, medium, medium, good, bad]
147
154
Categories (3, object): [bad < medium < good]
148
155
156
+ ``ordered=False`` will result in unordered categories when labels are passed:
157
+
158
+ >>> pd.cut(np.array([1, 7, 5, 4, 6, 3]),
159
+ ... 3, labels=["B", "C", "A"])
160
+ [B, A, C, C, A, B]
161
+ Categories (3, object): [B < C < A]
162
+
149
163
``labels=False`` implies you just want the bins back.
150
164
151
165
>>> pd.cut([0, 1, 1, 2], bins=4, labels=False)
0 commit comments