Skip to content

Commit eb974ce

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

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
@@ -6761,13 +6761,39 @@ def at_time(self, time, asof=False):
67616761
"""
67626762
Select values at particular time of day (e.g. 9:30AM).
67636763
6764+
Notes
6765+
-----
6766+
For this method to work, the index must to be a :class:`DatetimeIndex`
6767+
67646768
Parameters
67656769
----------
67666770
time : datetime.time or string
67676771
67686772
Returns
67696773
-------
67706774
values_at_time : type of caller
6775+
6776+
Examples
6777+
--------
6778+
>>> i = pd.date_range('2018-04-09', periods=4, freq='4D2min')
6779+
>>> ts = pd.DataFrame({'A': [1,2,3,4]}, index=i)
6780+
>>> ts
6781+
A
6782+
date
6783+
2018-04-09 00:00:00 1
6784+
2018-04-13 00:02:00 2
6785+
2018-04-17 00:04:00 3
6786+
2018-04-21 00:06:00 4
6787+
>>> ts.at_time('0:02')
6788+
A
6789+
date
6790+
2018-04-13 00:02:00 2
6791+
6792+
See Also
6793+
--------
6794+
between_time : Select values between particular times of the day
6795+
first : Select initial periods of time series based on a date offset
6796+
last : Select final periods of time series based on a date offset
67716797
"""
67726798
try:
67736799
indexer = self.index.indexer_at_time(time, asof=asof)
@@ -6780,6 +6806,10 @@ def between_time(self, start_time, end_time, include_start=True,
67806806
"""
67816807
Select values between particular times of the day (e.g., 9:00-9:30 AM).
67826808
6809+
Notes
6810+
-----
6811+
For this method to work, the index must to be a :class:`DatetimeIndex`
6812+
67836813
Parameters
67846814
----------
67856815
start_time : datetime.time or string
@@ -6790,6 +6820,27 @@ def between_time(self, start_time, end_time, include_start=True,
67906820
Returns
67916821
-------
67926822
values_between_time : type of caller
6823+
6824+
Examples
6825+
--------
6826+
>>> i = pd.date_range('2018-04-09', periods=4, freq='2min')
6827+
>>> ts = pd.DataFrame({'A': [1,2,3,4]}, index=i)
6828+
>>> ts
6829+
A
6830+
2018-04-09 00:00:00 1
6831+
2018-04-09 00:02:00 2
6832+
2018-04-09 00:04:00 3
6833+
2018-04-09 00:06:00 4
6834+
>>> ts.between_time('0:02', '0:04')
6835+
A
6836+
2018-04-09 00:02:00 2
6837+
2018-04-09 00:04:00 3
6838+
6839+
See Also
6840+
--------
6841+
at_time : Select values at a particular time of the day
6842+
first : Select initial periods of time series based on a date offset
6843+
last : Select final periods of time series based on a date offset
67936844
"""
67946845
try:
67956846
indexer = self.index.indexer_between_time(
@@ -7043,17 +7094,39 @@ def first(self, offset):
70437094
Convenience method for subsetting initial periods of time series data
70447095
based on a date offset.
70457096
7097+
Notes
7098+
-----
7099+
For this method to work, the index must to be a :class:`DatetimeIndex`
7100+
70467101
Parameters
70477102
----------
70487103
offset : string, DateOffset, dateutil.relativedelta
70497104
70507105
Examples
70517106
--------
7052-
ts.first('10D') -> First 10 days
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.first('3D')
7116+
A
7117+
2018-04-09 1
7118+
2018-04-10 2
7119+
2018-04-11 3
70537120
70547121
Returns
70557122
-------
70567123
subset : type of caller
7124+
7125+
See Also
7126+
--------
7127+
last : Select final 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
70577130
"""
70587131
from pandas.tseries.frequencies import to_offset
70597132
if not isinstance(self.index, DatetimeIndex):
@@ -7079,17 +7152,39 @@ def last(self, offset):
70797152
Convenience method for subsetting final periods of time series data
70807153
based on a date offset.
70817154
7155+
Notes
7156+
-----
7157+
For this method to work, the index must to be a :class:`DatetimeIndex`
7158+
70827159
Parameters
70837160
----------
70847161
offset : string, DateOffset, dateutil.relativedelta
70857162
70867163
Examples
70877164
--------
7088-
ts.last('5M') -> Last 5 months
7165+
>>> i = pd.date_range('2018-04-09', periods=4, freq='D')
7166+
>>> ts = pd.DataFrame({'A': [1,2,3,4]}, index=i)
7167+
>>> ts
7168+
A
7169+
2018-04-09 1
7170+
2018-04-10 2
7171+
2018-04-11 3
7172+
2018-04-12 4
7173+
>>> ts.last('3D')
7174+
A
7175+
2018-04-10 2
7176+
2018-04-11 3
7177+
2018-04-12 4
70897178
70907179
Returns
70917180
-------
70927181
subset : type of caller
7182+
7183+
See Also
7184+
--------
7185+
first : Select initial periods of time series based on a date offset
7186+
at_time : Select values at a particular time of the day
7187+
between_time : Select values between particular times of the day
70937188
"""
70947189
from pandas.tseries.frequencies import to_offset
70957190
if not isinstance(self.index, DatetimeIndex):

0 commit comments

Comments
 (0)