From e3cd0af8497ef70e4b028b2a8ece556ae67dc3d2 Mon Sep 17 00:00:00 2001 From: pilkibun Date: Fri, 28 Jun 2019 15:53:25 +0300 Subject: [PATCH 1/4] DOC: tweak paragraph regarding cut and IntervalIndex --- doc/source/user_guide/advanced.rst | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/doc/source/user_guide/advanced.rst b/doc/source/user_guide/advanced.rst index 280eb05964787..e1c761c01c592 100644 --- a/doc/source/user_guide/advanced.rst +++ b/doc/source/user_guide/advanced.rst @@ -965,7 +965,8 @@ If you select a label *contained* within an interval, this will also select the df.loc[2.5] df.loc[[2.5, 3.5]] -``Interval`` and ``IntervalIndex`` are used by ``cut`` and ``qcut``: +:func:`cut` and :func:`qcut` both return a ``Categorical`` object, and the bins they +create are stored as an ``IntervalIndex`` in its `.categories` attribute. .. ipython:: python @@ -973,13 +974,19 @@ If you select a label *contained* within an interval, this will also select the c c.categories -Furthermore, ``IntervalIndex`` allows one to bin *other* data with these same -bins, with ``NaN`` representing a missing value similar to other dtypes. +:func:`cut` also accepts an ``IntervalIndex`` for its `bins` argument, which enables +a useful pandas idiom. We call :func:`cut` once on some data with `bins` set to a +fixed number, to generate the bins. We can then pass `.categories` as the `bins` argument +in subsequent calls to :func:`cut`, to have the new data binned into the same bins. .. ipython:: python pd.cut([0, 3, 5, 1], bins=c.categories) +When :func:`cut` is passed an ``IntervalIndex`` for the `bins` argument, The ``Interval`` +values in the ``IntervalIndex`` define the bins and any value which falls outside all bins +will be assigned a ``NaN`` value. + Generating ranges of intervals ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From 87e4495dfbfc7d4aeb2ff0b37d00110498cdbf36 Mon Sep 17 00:00:00 2001 From: pilkibun Date: Sun, 30 Jun 2019 22:55:07 +0300 Subject: [PATCH 2/4] Use double ticks --- doc/source/user_guide/advanced.rst | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/doc/source/user_guide/advanced.rst b/doc/source/user_guide/advanced.rst index e1c761c01c592..d1ea6a0fe3aff 100644 --- a/doc/source/user_guide/advanced.rst +++ b/doc/source/user_guide/advanced.rst @@ -966,7 +966,7 @@ If you select a label *contained* within an interval, this will also select the df.loc[[2.5, 3.5]] :func:`cut` and :func:`qcut` both return a ``Categorical`` object, and the bins they -create are stored as an ``IntervalIndex`` in its `.categories` attribute. +create are stored as an ``IntervalIndex`` in its ``.categories`` attribute. .. ipython:: python @@ -974,18 +974,19 @@ create are stored as an ``IntervalIndex`` in its `.categories` attribute. c c.categories -:func:`cut` also accepts an ``IntervalIndex`` for its `bins` argument, which enables -a useful pandas idiom. We call :func:`cut` once on some data with `bins` set to a -fixed number, to generate the bins. We can then pass `.categories` as the `bins` argument -in subsequent calls to :func:`cut`, to have the new data binned into the same bins. +:func:`cut` also accepts an ``IntervalIndex`` for its ``bins`` argument, which enables +a useful pandas idiom. First, We call :func:`cut` with some data and ``bins`` set to a +fixed number, to establish the bins. Then, we can pass the value of ``.categories`` as +the ``bins`` argument in subsequent calls to :func:`cut`, supplying new data which +will be binned into the same bins. .. ipython:: python pd.cut([0, 3, 5, 1], bins=c.categories) When :func:`cut` is passed an ``IntervalIndex`` for the `bins` argument, The ``Interval`` -values in the ``IntervalIndex`` define the bins and any value which falls outside all bins -will be assigned a ``NaN`` value. +values in the ``IntervalIndex`` define the bins and any value which falls outside all +bins will be assigned a ``NaN`` value. Generating ranges of intervals From b747753e549113c1ad66a357cd37119e7720a290 Mon Sep 17 00:00:00 2001 From: pilkibun Date: Sun, 30 Jun 2019 23:55:26 +0300 Subject: [PATCH 3/4] Trim --- doc/source/user_guide/advanced.rst | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/doc/source/user_guide/advanced.rst b/doc/source/user_guide/advanced.rst index d1ea6a0fe3aff..40bd3792d6a77 100644 --- a/doc/source/user_guide/advanced.rst +++ b/doc/source/user_guide/advanced.rst @@ -976,17 +976,15 @@ create are stored as an ``IntervalIndex`` in its ``.categories`` attribute. :func:`cut` also accepts an ``IntervalIndex`` for its ``bins`` argument, which enables a useful pandas idiom. First, We call :func:`cut` with some data and ``bins`` set to a -fixed number, to establish the bins. Then, we can pass the value of ``.categories`` as -the ``bins`` argument in subsequent calls to :func:`cut`, supplying new data which -will be binned into the same bins. +fixed number, to generate the bins. Then, we pass the values of ``.categories`` as the +``bins`` argument in subsequent calls to :func:`cut`, supplying new data which will be +binned into the same bins. .. ipython:: python pd.cut([0, 3, 5, 1], bins=c.categories) -When :func:`cut` is passed an ``IntervalIndex`` for the `bins` argument, The ``Interval`` -values in the ``IntervalIndex`` define the bins and any value which falls outside all -bins will be assigned a ``NaN`` value. +Any value which falls outside all bins will be assigned a ``NaN`` value. Generating ranges of intervals From 7cf0aa7984e18309cdc0c6ce76bf992d798790b0 Mon Sep 17 00:00:00 2001 From: pilkibun Date: Sun, 30 Jun 2019 23:56:24 +0300 Subject: [PATCH 4/4] whitespace --- doc/source/user_guide/advanced.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/source/user_guide/advanced.rst b/doc/source/user_guide/advanced.rst index 40bd3792d6a77..f67b7cfa05c76 100644 --- a/doc/source/user_guide/advanced.rst +++ b/doc/source/user_guide/advanced.rst @@ -986,7 +986,6 @@ binned into the same bins. Any value which falls outside all bins will be assigned a ``NaN`` value. - Generating ranges of intervals ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^