You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/source/indexing.rst
+13-4
Original file line number
Diff line number
Diff line change
@@ -78,8 +78,12 @@ of multi-axis indexing.
78
78
*label* of the index. This use is **not** an integer position along the
79
79
index)
80
80
- A list or array of labels ``['a', 'b', 'c']``
81
-
- A slice object with labels ``'a':'f'``, (note that contrary to usual python
82
-
slices, **both** the start and the stop are included!)
81
+
- A slice object with labels ``'a':'f'``: note that contrary to usual python
82
+
slices, **both** the start and the stop are included, when present in the
83
+
index! If at least one of the two is absent but the index elements are
84
+
sorted (and can be compared against start and stop labels), then slicing
85
+
will still work as expected, that is, selecting labels which rank between
86
+
``'a'`` and ``'f'``.
83
87
- A boolean array
84
88
- A ``callable`` function with one argument (the calling Series, DataFrame or Panel) and
85
89
that returns valid output for indexing (one of the above)
@@ -330,13 +334,18 @@ Selection By Label
330
334
dfl.loc['20130102':'20130104']
331
335
332
336
pandas provides a suite of methods in order to have **purely label based indexing**. This is a strict inclusion based protocol.
333
-
**At least 1** of the labels for which you ask, must be in the index or a ``KeyError`` will be raised! When slicing, the start bound is *included*, **AND** the stop bound is *included*. Integers are valid labels, but they refer to the label **and not the position**.
337
+
**At least 1** of the labels for which you ask, must be in the index or a ``KeyError`` will be raised! When slicing, both the start bound **AND** the stop bound are *included*, if present in the index. Integers are valid labels, but they refer to the label **and not the position**.
334
338
335
339
The ``.loc`` attribute is the primary access method. The following are valid inputs:
336
340
337
341
- A single label, e.g. ``5`` or ``'a'``, (note that ``5`` is interpreted as a *label* of the index. This use is **not** an integer position along the index)
338
342
- A list or array of labels ``['a', 'b', 'c']``
339
-
- A slice object with labels ``'a':'f'`` (note that contrary to usual python slices, **both** the start and the stop are included!)
343
+
- A slice object with labels ``'a':'f'``: note that contrary to usual python
344
+
slices, **both** the start and the stop are included, when present in the
345
+
index! If at least one of the two is absent but the index elements are sorted
346
+
(and can be compared against start and stop labels), then slicing will still
347
+
work as expected, that is selecting labels which rank between ``'a'`` and
348
+
``'f'``.
340
349
- A boolean array
341
350
- A ``callable``, see :ref:`Selection By Callable <indexing.callable>`
0 commit comments