Skip to content

Commit 834df76

Browse files
committed
more docs
1 parent fbc1cf8 commit 834df76

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

doc/source/whatsnew/v0.20.0.txt

+32-6
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,11 @@ To convert a ``SparseDataFrame`` back to sparse SciPy matrix in COO format, you
320320
IntervalIndex
321321
^^^^^^^^^^^^^
322322

323-
pandas has gain an ``IntervalIndex`` with its own dtype, ``interval`` as well as the ``Interval`` scalar type. These allow first-class support for interval
324-
notation, specifically as return type for ``pd.cut`` and ``pd.qcut``. The ``IntervalIndex`` allows some unique indexing, see the
323+
pandas has gained an ``IntervalIndex`` with its own dtype, ``interval`` as well as the ``Interval`` scalar type. These allow first-class support for interval
324+
notation, specifically as a return type for the categories in ``pd.cut`` and ``pd.qcut``. The ``IntervalIndex`` allows some unique indexing, see the
325325
:ref:`docs <indexing.intervallindex>`. (:issue:`7640`, :issue:`8625`)
326326

327-
**Previous behavior**:
327+
Previous behavior:
328328

329329
.. code-block:: ipython
330330

@@ -337,14 +337,40 @@ notation, specifically as return type for ``pd.cut`` and ``pd.qcut``. The ``Inte
337337
In [3]: pd.cut(range(3), 2).categories
338338
Out[3]: Index(['(-0.002, 1]', '(1, 2]'], dtype='object')
339339

340-
**New behavior**:
340+
New behavior:
341341

342342
.. ipython:: python
343343

344-
c = pd.cut(range(3), 2)
344+
c = pd.cut(range(4), bins=2)
345345
c
346346
c.categories
347-
pd.api.types.is_interval_dtype(c.categories)
347+
348+
Furthermore, this allows one to bin *other* data with these same bins. ``NaN`` represents a missing
349+
value similar to other dtypes.
350+
351+
.. ipython:: python
352+
353+
pd.cut([0, 3, 1, 1], bins=c.categories)
354+
355+
These can also used in ``Series`` and ``DataFrame``, and indexed.
356+
357+
.. ipython:: python
358+
359+
df = pd.DataFrame({'A': range(4),
360+
'B': pd.cut([0, 3, 1, 1], bins=c.categories)}
361+
).set_index('B')
362+
363+
Selecting a specific interval
364+
365+
.. ipython:: python
366+
367+
df.loc[pd.Interval(1.5, 3.0)]
368+
369+
Selecting via a scalar value that is contained in the intervals.
370+
371+
.. ipython:: python
372+
373+
df.loc[0]
348374

349375
.. _whatsnew_0200.enhancements.other:
350376

0 commit comments

Comments
 (0)