@@ -142,12 +142,17 @@ def cut(
142
142
fixed set of values.
143
143
Series : One-dimensional array with axis labels (including time series).
144
144
IntervalIndex : Immutable Index implementing an ordered, sliceable set.
145
+ numpy.histogram_bin_edges: Function to calculate only the edges of the bins
146
+ used by the histogram function.
145
147
146
148
Notes
147
149
-----
148
150
Any NA values will be NA in the result. Out of bounds values will be NA in
149
151
the resulting Series or Categorical object.
150
152
153
+ ``numpy.histogram_bin_edges`` can be used along with cut to calculate bins according
154
+ to some predefined methods.
155
+
151
156
Reference :ref:`the user guide <reshaping.tile.cut>` for more examples.
152
157
153
158
Examples
@@ -239,6 +244,16 @@ def cut(
239
244
>>> pd.cut([0, 0.5, 1.5, 2.5, 4.5], bins)
240
245
[NaN, (0.0, 1.0], NaN, (2.0, 3.0], (4.0, 5.0]]
241
246
Categories (3, interval[int64, right]): [(0, 1] < (2, 3] < (4, 5]]
247
+
248
+ Using np.histogram_bin_edges with cut
249
+
250
+ >>> pd.cut(
251
+ ... np.array([1, 7, 5, 4]),
252
+ ... bins=np.histogram_bin_edges(np.array([1, 7, 5, 4]), bins="auto"),
253
+ ... )
254
+ ... # doctest: +ELLIPSIS
255
+ [NaN, (5.0, 7.0], (3.0, 5.0], (3.0, 5.0]]
256
+ Categories (3, interval[float64, right]): [(1.0, 3.0] < (3.0, 5.0] < (5.0, 7.0]]
242
257
"""
243
258
# NOTE: this binning code is changed a bit from histogram for var(x) == 0
244
259
0 commit comments