Skip to content

Commit efb99be

Browse files
chaarviiasishmmroeschke
authored
DOC: Using np.histogram_bin_edges with pd.cut (pandas-dev#59281)
* update documentation * Update pandas/core/reshape/tile.py Co-authored-by: Asish Mahapatra <[email protected]> * Update pandas/core/reshape/tile.py Co-authored-by: Matthew Roeschke <[email protected]> --------- Co-authored-by: Asish Mahapatra <[email protected]> Co-authored-by: Matthew Roeschke <[email protected]>
1 parent 04424b0 commit efb99be

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

pandas/core/reshape/tile.py

+15
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,17 @@ def cut(
142142
fixed set of values.
143143
Series : One-dimensional array with axis labels (including time series).
144144
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.
145147
146148
Notes
147149
-----
148150
Any NA values will be NA in the result. Out of bounds values will be NA in
149151
the resulting Series or Categorical object.
150152
153+
``numpy.histogram_bin_edges`` can be used along with cut to calculate bins according
154+
to some predefined methods.
155+
151156
Reference :ref:`the user guide <reshaping.tile.cut>` for more examples.
152157
153158
Examples
@@ -239,6 +244,16 @@ def cut(
239244
>>> pd.cut([0, 0.5, 1.5, 2.5, 4.5], bins)
240245
[NaN, (0.0, 1.0], NaN, (2.0, 3.0], (4.0, 5.0]]
241246
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]]
242257
"""
243258
# NOTE: this binning code is changed a bit from histogram for var(x) == 0
244259

0 commit comments

Comments
 (0)