Skip to content

Commit 81f6b51

Browse files
author
tp
committed
improve doc strings, also indexer_at/between_/time
1 parent 1f6907b commit 81f6b51

File tree

2 files changed

+52
-24
lines changed

2 files changed

+52
-24
lines changed

pandas/core/generic.py

+30-15
Original file line numberDiff line numberDiff line change
@@ -6717,25 +6717,26 @@ def at_time(self, time, asof=False):
67176717
67186718
Examples
67196719
--------
6720-
>>> i = pd.date_range('2018-04-09', periods=4, freq='4D2min')
6720+
>>> i = pd.date_range('2018-04-09', periods=4, freq='12H')
67216721
>>> ts = pd.DataFrame({'A': [1,2,3,4]}, index=i)
67226722
>>> ts
67236723
A
6724-
date
67256724
2018-04-09 00:00:00 1
6726-
2018-04-13 00:02:00 2
6727-
2018-04-17 00:04:00 3
6728-
2018-04-21 00:06:00 4
6729-
>>> ts.at_time('0:02')
6725+
2018-04-09 12:00:00 2
6726+
2018-04-10 00:00:00 3
6727+
2018-04-10 12:00:00 4
6728+
>>> ts.at_time('12:00')
67306729
A
6731-
date
6732-
2018-04-13 00:02:00 2
6730+
2018-04-09 12:00:00 2
6731+
2018-04-10 12:00:00 4
67336732
67346733
See Also
67356734
--------
67366735
between_time : Select values between particular times of the day
67376736
first : Select initial periods of time series based on a date offset
67386737
last : Select final periods of time series based on a date offset
6738+
DatetimeIndex.indexer_at_time : Get just the index positions for
6739+
values at particular time of the day
67396740
"""
67406741
try:
67416742
indexer = self.index.indexer_at_time(time, asof=asof)
@@ -6748,6 +6749,9 @@ def between_time(self, start_time, end_time, include_start=True,
67486749
"""
67496750
Select values between particular times of the day (e.g., 9:00-9:30 AM).
67506751
6752+
By setting ``start_time`` to be later than ``end_time``,
6753+
you can get the times that are *not* between the two times.
6754+
67516755
Notes
67526756
-----
67536757
For this method to work, the index must to be a :class:`DatetimeIndex`
@@ -6765,24 +6769,35 @@ def between_time(self, start_time, end_time, include_start=True,
67656769
67666770
Examples
67676771
--------
6768-
>>> i = pd.date_range('2018-04-09', periods=4, freq='2min')
6772+
>>> i = pd.date_range('2018-04-09', periods=4, freq='1D20min')
67696773
>>> ts = pd.DataFrame({'A': [1,2,3,4]}, index=i)
67706774
>>> ts
67716775
A
67726776
2018-04-09 00:00:00 1
6773-
2018-04-09 00:02:00 2
6774-
2018-04-09 00:04:00 3
6775-
2018-04-09 00:06:00 4
6776-
>>> ts.between_time('0:02', '0:04')
6777+
2018-04-10 00:20:00 2
6778+
2018-04-11 00:40:00 3
6779+
2018-04-12 01:00:00 4
6780+
6781+
>>> ts.between_time('0:15', '0:45')
6782+
A
6783+
2018-04-10 00:20:00 2
6784+
2018-04-11 00:40:00 3
6785+
6786+
You get the times that are *not* between two times by setting
6787+
``start_time`` later than ``end_time``:
6788+
6789+
>>> ts.between_time('0:45', '0:15')
67776790
A
6778-
2018-04-09 00:02:00 2
6779-
2018-04-09 00:04:00 3
6791+
2018-04-09 00:00:00 1
6792+
2018-04-12 01:00:00 4
67806793
67816794
See Also
67826795
--------
67836796
at_time : Select values at a particular time of the day
67846797
first : Select initial periods of time series based on a date offset
67856798
last : Select final periods of time series based on a date offset
6799+
DatetimeIndex.indexer_between_time : Get just the index positions for
6800+
values between particular times of the day
67866801
"""
67876802
try:
67886803
indexer = self.index.indexer_between_time(

pandas/core/indexes/datetimes.py

+22-9
Original file line numberDiff line numberDiff line change
@@ -2378,15 +2378,25 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'):
23782378

23792379
def indexer_at_time(self, time, asof=False):
23802380
"""
2381-
Select values at particular time of day (e.g. 9:30AM)
2381+
Returns index positions of index values at particular time of day
2382+
(e.g. 9:30AM).
23822383
23832384
Parameters
23842385
----------
23852386
time : datetime.time or string
2387+
datetime.time or string in appropriate format ("%H:%M", "%H%M",
2388+
"%I:%M%p", "%I%M%p", "%H:%M:%S", "%H%M%S", "%I:%M:%S%p",
2389+
"%I%M%S%p").
2390+
If strings, then ``tseries.tools.to_time`` is used to convert to
2391+
a time object.
23862392
23872393
Returns
23882394
-------
2389-
values_at_time : TimeSeries
2395+
values_at_time : array
2396+
2397+
See Also
2398+
--------
2399+
indexer_between_time, DataFrame.at_time
23902400
"""
23912401
from dateutil.parser import parse
23922402

@@ -2408,24 +2418,27 @@ def indexer_at_time(self, time, asof=False):
24082418
def indexer_between_time(self, start_time, end_time, include_start=True,
24092419
include_end=True):
24102420
"""
2411-
Select values between particular times of day (e.g., 9:00-9:30AM).
2412-
2413-
Return values of the index between two times. If start_time or
2414-
end_time are strings then tseries.tools.to_time is used to convert to
2415-
a time object.
2421+
Return index positions of values between particular times of day
2422+
(e.g., 9:00-9:30AM).
24162423
24172424
Parameters
24182425
----------
24192426
start_time, end_time : datetime.time, str
24202427
datetime.time or string in appropriate format ("%H:%M", "%H%M",
24212428
"%I:%M%p", "%I%M%p", "%H:%M:%S", "%H%M%S", "%I:%M:%S%p",
2422-
"%I%M%S%p")
2429+
"%I%M%S%p").
2430+
If strings, then ``tseries.tools.to_time`` is used to convert to
2431+
a time object.
24232432
include_start : boolean, default True
24242433
include_end : boolean, default True
24252434
24262435
Returns
24272436
-------
2428-
values_between_time : TimeSeries
2437+
values_between_time : array
2438+
2439+
See Also
2440+
--------
2441+
indexer_at_time, DataFrame.between_time
24292442
"""
24302443
start_time = tools.to_time(start_time)
24312444
end_time = tools.to_time(end_time)

0 commit comments

Comments
 (0)