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/timeseries.rst
+39-16
Original file line number
Diff line number
Diff line change
@@ -457,22 +457,6 @@ We are stopping on the included end-point as it is part of the index
457
457
458
458
dft['2013-1-15':'2013-1-15 12:30:00']
459
459
460
-
.. warning::
461
-
462
-
The following selection will raise a ``KeyError``; otherwise this selection methodology
463
-
would be inconsistent with other selection methods in pandas (as this is not a *slice*, nor does it
464
-
resolve to one)
465
-
466
-
.. code-block:: python
467
-
468
-
dft['2013-1-15 12:30:00']
469
-
470
-
To select a single row, use ``.loc``
471
-
472
-
.. ipython:: python
473
-
474
-
dft.loc['2013-1-15 12:30:00']
475
-
476
460
.. versionadded:: 0.18.0
477
461
478
462
DatetimeIndex Partial String Indexing also works on DataFrames with a ``MultiIndex``. For example:
@@ -491,6 +475,45 @@ DatetimeIndex Partial String Indexing also works on DataFrames with a ``MultiInd
491
475
dft2 = dft2.swaplevel(0, 1).sort_index()
492
476
dft2.loc[idx[:, '2013-01-05'], :]
493
477
478
+
String Indexing: slice vs. exact match
479
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
480
+
481
+
The same string used as an indexing parameter can be treated either as slice or as exact match depending on the resolution of an index. If the string is less precise than index, it will be treated as a slice, otherwise as an exact match.
series_second['2012-12-31 23:59'] # now it returns scalar
496
+
497
+
It also works for ``DataFrame``:
498
+
499
+
.. ipython:: python
500
+
dft_minute = pd.DataFrame(series_minute)
501
+
dft_minute['2011-12-31 23']
502
+
503
+
.. warning::
504
+
505
+
If a string used in ``DataFrame``'s ``[]`` indexing is treated as an exact match the selection will be column-wise and not row-wise. This is consistent with :ref:`Indexing Basics <indexing.basics>`. For example, the following code will raise ``KeyError`` as there is no column with index ``'2012-12-31 23:59'``:
Copy file name to clipboardExpand all lines: doc/source/whatsnew/v0.20.0.txt
+32
Original file line number
Diff line number
Diff line change
@@ -70,6 +70,38 @@ Backwards incompatible API changes
70
70
Other API Changes
71
71
^^^^^^^^^^^^^^^^^
72
72
73
+
- :ref:`DatetimeIndex Partial String Indexing <timeseries.partialindexing>` now works as exact match provided that string resolution coincides with index resolution (:issue:`14826`).
0 commit comments