Skip to content

Commit 40eddc3

Browse files
committed
- Documentation fixes
1 parent e17d210 commit 40eddc3

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

doc/source/timeseries.rst

+21-15
Original file line numberDiff line numberDiff line change
@@ -475,44 +475,50 @@ DatetimeIndex Partial String Indexing also works on DataFrames with a ``MultiInd
475475
dft2 = dft2.swaplevel(0, 1).sort_index()
476476
dft2.loc[idx[:, '2013-01-05'], :]
477477
478-
String Indexing: slice vs. exact match
479-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
478+
Slice vs. exact match
479+
^^^^^^^^^^^^^^^^^^^^^
480480

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.
481+
The same string used as an indexing parameter can be treated either as a slice or as an exact match depending on the resolution of an index. If the string is less accurate than the index, it will be treated as a slice, otherwise as an exact match.
482482

483483
.. ipython:: python
484-
series_minute = pd.Series([1, 2, 3], DatetimeIndex(['2011-12-31 23:59:00',
485-
'2012-01-01 00:00:00',
486-
'2012-01-01 00:01:00']))
484+
485+
series_minute = pd.Series([1, 2, 3],
486+
pd.DatetimeIndex(['2011-12-31 23:59:00',
487+
'2012-01-01 00:00:00',
488+
'2012-01-01 00:01:00']))
487489
series_minute.index.resolution
488490
series_minute['2011-12-31 23'] # returns Series
489-
series_minute['2012-12-31 23:59'] # returns scalar
491+
series_minute['2011-12-31 23:59'] # returns scalar
490492
491-
series_second = pd.Series([1, 2, 3], DatetimeIndex(['2011-12-31 23:59:59',
492-
'2012-01-01 00:00:00',
493-
'2012-01-01 00:00:01']))
493+
series_second = pd.Series([1, 2, 3],
494+
pd.DatetimeIndex(['2011-12-31 23:59:59',
495+
'2012-01-01 00:00:00',
496+
'2012-01-01 00:00:01']))
494497
series_second.index.resolution
495-
series_second['2012-12-31 23:59'] # now it returns scalar
498+
series_second['2011-12-31 23:59'] # now it returns Series
496499
497500
It also works for ``DataFrame``:
498501

499502
.. ipython:: python
500-
dft_minute = pd.DataFrame(series_minute)
503+
504+
dft_minute = pd.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6]},
505+
index=series_minute.index)
501506
dft_minute['2011-12-31 23']
502507
503508
.. warning::
504509

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'``:
510+
If 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'``:
506511

507512
.. code-block:: python
508513
509-
df_minute['2012-12-31 23:59']
514+
dft_minute['2011-12-31 23:59']
515+
# KeyError: '2011-12-31 23:59'
510516
511517
To select a single row, use ``.loc``
512518

513519
.. ipython:: python
514520
515-
df_minute.loc['2012-12-31 23:59']
521+
dft_minute.loc['2011-12-31 23:59']
516522
517523
Datetime Indexing
518524
~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)