Skip to content

Commit 1f6907b

Browse files
author
tp
committed
add Notes, Examples and See Also to at_time/between_time/first/last
1 parent 3a2e9e6 commit 1f6907b

File tree

1 file changed

+97
-2
lines changed

1 file changed

+97
-2
lines changed

pandas/core/generic.py

+97-2
Original file line numberDiff line numberDiff line change
@@ -6703,13 +6703,39 @@ def at_time(self, time, asof=False):
67036703
"""
67046704
Select values at particular time of day (e.g. 9:30AM).
67056705
6706+
Notes
6707+
-----
6708+
For this method to work, the index must to be a :class:`DatetimeIndex`
6709+
67066710
Parameters
67076711
----------
67086712
time : datetime.time or string
67096713
67106714
Returns
67116715
-------
67126716
values_at_time : type of caller
6717+
6718+
Examples
6719+
--------
6720+
>>> i = pd.date_range('2018-04-09', periods=4, freq='4D2min')
6721+
>>> ts = pd.DataFrame({'A': [1,2,3,4]}, index=i)
6722+
>>> ts
6723+
A
6724+
date
6725+
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')
6730+
A
6731+
date
6732+
2018-04-13 00:02:00 2
6733+
6734+
See Also
6735+
--------
6736+
between_time : Select values between particular times of the day
6737+
first : Select initial periods of time series based on a date offset
6738+
last : Select final periods of time series based on a date offset
67136739
"""
67146740
try:
67156741
indexer = self.index.indexer_at_time(time, asof=asof)
@@ -6722,6 +6748,10 @@ def between_time(self, start_time, end_time, include_start=True,
67226748
"""
67236749
Select values between particular times of the day (e.g., 9:00-9:30 AM).
67246750
6751+
Notes
6752+
-----
6753+
For this method to work, the index must to be a :class:`DatetimeIndex`
6754+
67256755
Parameters
67266756
----------
67276757
start_time : datetime.time or string
@@ -6732,6 +6762,27 @@ def between_time(self, start_time, end_time, include_start=True,
67326762
Returns
67336763
-------
67346764
values_between_time : type of caller
6765+
6766+
Examples
6767+
--------
6768+
>>> i = pd.date_range('2018-04-09', periods=4, freq='2min')
6769+
>>> ts = pd.DataFrame({'A': [1,2,3,4]}, index=i)
6770+
>>> ts
6771+
A
6772+
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+
A
6778+
2018-04-09 00:02:00 2
6779+
2018-04-09 00:04:00 3
6780+
6781+
See Also
6782+
--------
6783+
at_time : Select values at a particular time of the day
6784+
first : Select initial periods of time series based on a date offset
6785+
last : Select final periods of time series based on a date offset
67356786
"""
67366787
try:
67376788
indexer = self.index.indexer_between_time(
@@ -6985,17 +7036,39 @@ def first(self, offset):
69857036
Convenience method for subsetting initial periods of time series data
69867037
based on a date offset.
69877038
7039+
Notes
7040+
-----
7041+
For this method to work, the index must to be a :class:`DatetimeIndex`
7042+
69887043
Parameters
69897044
----------
69907045
offset : string, DateOffset, dateutil.relativedelta
69917046
69927047
Examples
69937048
--------
6994-
ts.first('10D') -> First 10 days
7049+
>>> i = pd.date_range('2018-04-09', periods=4, freq='D')
7050+
>>> ts = pd.DataFrame({'A': [1,2,3,4]}, index=i)
7051+
>>> ts
7052+
A
7053+
2018-04-09 1
7054+
2018-04-10 2
7055+
2018-04-11 3
7056+
2018-04-12 4
7057+
>>> ts.first('3D')
7058+
A
7059+
2018-04-09 1
7060+
2018-04-10 2
7061+
2018-04-11 3
69957062
69967063
Returns
69977064
-------
69987065
subset : type of caller
7066+
7067+
See Also
7068+
--------
7069+
last : Select final periods of time series based on a date offset
7070+
at_time : Select values at a particular time of the day
7071+
between_time : Select values between particular times of the day
69997072
"""
70007073
from pandas.tseries.frequencies import to_offset
70017074
if not isinstance(self.index, DatetimeIndex):
@@ -7021,17 +7094,39 @@ def last(self, offset):
70217094
Convenience method for subsetting final periods of time series data
70227095
based on a date offset.
70237096
7097+
Notes
7098+
-----
7099+
For this method to work, the index must to be a :class:`DatetimeIndex`
7100+
70247101
Parameters
70257102
----------
70267103
offset : string, DateOffset, dateutil.relativedelta
70277104
70287105
Examples
70297106
--------
7030-
ts.last('5M') -> Last 5 months
7107+
>>> i = pd.date_range('2018-04-09', periods=4, freq='D')
7108+
>>> ts = pd.DataFrame({'A': [1,2,3,4]}, index=i)
7109+
>>> ts
7110+
A
7111+
2018-04-09 1
7112+
2018-04-10 2
7113+
2018-04-11 3
7114+
2018-04-12 4
7115+
>>> ts.last('3D')
7116+
A
7117+
2018-04-10 2
7118+
2018-04-11 3
7119+
2018-04-12 4
70317120
70327121
Returns
70337122
-------
70347123
subset : type of caller
7124+
7125+
See Also
7126+
--------
7127+
first : Select initial periods of time series based on a date offset
7128+
at_time : Select values at a particular time of the day
7129+
between_time : Select values between particular times of the day
70357130
"""
70367131
from pandas.tseries.frequencies import to_offset
70377132
if not isinstance(self.index, DatetimeIndex):

0 commit comments

Comments
 (0)