Skip to content

Commit ecb1592

Browse files
author
tp
committed
add Notes, Examples and See Also to at_time/between_time/first/last
1 parent 0d199e4 commit ecb1592

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
@@ -6704,13 +6704,39 @@ def at_time(self, time, asof=False):
67046704
"""
67056705
Select values at particular time of day (e.g. 9:30AM).
67066706
6707+
Notes
6708+
-----
6709+
For this method to work, the index must to be a :class:`DatetimeIndex`
6710+
67076711
Parameters
67086712
----------
67096713
time : datetime.time or string
67106714
67116715
Returns
67126716
-------
67136717
values_at_time : type of caller
6718+
6719+
Examples
6720+
--------
6721+
>>> i = pd.date_range('2018-04-09', periods=4, freq='4D2min')
6722+
>>> ts = pd.DataFrame({'A': [1,2,3,4]}, index=i)
6723+
>>> ts
6724+
A
6725+
date
6726+
2018-04-09 00:00:00 1
6727+
2018-04-13 00:02:00 2
6728+
2018-04-17 00:04:00 3
6729+
2018-04-21 00:06:00 4
6730+
>>> ts.at_time('0:02')
6731+
A
6732+
date
6733+
2018-04-13 00:02:00 2
6734+
6735+
See Also
6736+
--------
6737+
between_time : Select values between particular times of the day
6738+
first : Select initial periods of time series based on a date offset
6739+
last : Select final periods of time series based on a date offset
67146740
"""
67156741
try:
67166742
indexer = self.index.indexer_at_time(time, asof=asof)
@@ -6723,6 +6749,10 @@ def between_time(self, start_time, end_time, include_start=True,
67236749
"""
67246750
Select values between particular times of the day (e.g., 9:00-9:30 AM).
67256751
6752+
Notes
6753+
-----
6754+
For this method to work, the index must to be a :class:`DatetimeIndex`
6755+
67266756
Parameters
67276757
----------
67286758
start_time : datetime.time or string
@@ -6733,6 +6763,27 @@ def between_time(self, start_time, end_time, include_start=True,
67336763
Returns
67346764
-------
67356765
values_between_time : type of caller
6766+
6767+
Examples
6768+
--------
6769+
>>> i = pd.date_range('2018-04-09', periods=4, freq='2min')
6770+
>>> ts = pd.DataFrame({'A': [1,2,3,4]}, index=i)
6771+
>>> ts
6772+
A
6773+
2018-04-09 00:00:00 1
6774+
2018-04-09 00:02:00 2
6775+
2018-04-09 00:04:00 3
6776+
2018-04-09 00:06:00 4
6777+
>>> ts.between_time('0:02', '0:04')
6778+
A
6779+
2018-04-09 00:02:00 2
6780+
2018-04-09 00:04:00 3
6781+
6782+
See Also
6783+
--------
6784+
at_time : Select values at a particular time of the day
6785+
first : Select initial periods of time series based on a date offset
6786+
last : Select final periods of time series based on a date offset
67366787
"""
67376788
try:
67386789
indexer = self.index.indexer_between_time(
@@ -6986,17 +7037,39 @@ def first(self, offset):
69867037
Convenience method for subsetting initial periods of time series data
69877038
based on a date offset.
69887039
7040+
Notes
7041+
-----
7042+
For this method to work, the index must to be a :class:`DatetimeIndex`
7043+
69897044
Parameters
69907045
----------
69917046
offset : string, DateOffset, dateutil.relativedelta
69927047
69937048
Examples
69947049
--------
6995-
ts.first('10D') -> First 10 days
7050+
>>> i = pd.date_range('2018-04-09', periods=4, freq='D')
7051+
>>> ts = pd.DataFrame({'A': [1,2,3,4]}, index=i)
7052+
>>> ts
7053+
A
7054+
2018-04-09 1
7055+
2018-04-10 2
7056+
2018-04-11 3
7057+
2018-04-12 4
7058+
>>> ts.first('3D')
7059+
A
7060+
2018-04-09 1
7061+
2018-04-10 2
7062+
2018-04-11 3
69967063
69977064
Returns
69987065
-------
69997066
subset : type of caller
7067+
7068+
See Also
7069+
--------
7070+
last : Select final periods of time series based on a date offset
7071+
at_time : Select values at a particular time of the day
7072+
between_time : Select values between particular times of the day
70007073
"""
70017074
from pandas.tseries.frequencies import to_offset
70027075
if not isinstance(self.index, DatetimeIndex):
@@ -7022,17 +7095,39 @@ def last(self, offset):
70227095
Convenience method for subsetting final periods of time series data
70237096
based on a date offset.
70247097
7098+
Notes
7099+
-----
7100+
For this method to work, the index must to be a :class:`DatetimeIndex`
7101+
70257102
Parameters
70267103
----------
70277104
offset : string, DateOffset, dateutil.relativedelta
70287105
70297106
Examples
70307107
--------
7031-
ts.last('5M') -> Last 5 months
7108+
>>> i = pd.date_range('2018-04-09', periods=4, freq='D')
7109+
>>> ts = pd.DataFrame({'A': [1,2,3,4]}, index=i)
7110+
>>> ts
7111+
A
7112+
2018-04-09 1
7113+
2018-04-10 2
7114+
2018-04-11 3
7115+
2018-04-12 4
7116+
>>> ts.last('3D')
7117+
A
7118+
2018-04-10 2
7119+
2018-04-11 3
7120+
2018-04-12 4
70327121
70337122
Returns
70347123
-------
70357124
subset : type of caller
7125+
7126+
See Also
7127+
--------
7128+
first : Select initial periods of time series based on a date offset
7129+
at_time : Select values at a particular time of the day
7130+
between_time : Select values between particular times of the day
70367131
"""
70377132
from pandas.tseries.frequencies import to_offset
70387133
if not isinstance(self.index, DatetimeIndex):

0 commit comments

Comments
 (0)