Skip to content

Commit aa4c928

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

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
@@ -6770,13 +6770,39 @@ def at_time(self, time, asof=False):
67706770
"""
67716771
Select values at particular time of day (e.g. 9:30AM).
67726772
6773+
Notes
6774+
-----
6775+
For this method to work, the index must to be a :class:`DatetimeIndex`
6776+
67736777
Parameters
67746778
----------
67756779
time : datetime.time or string
67766780
67776781
Returns
67786782
-------
67796783
values_at_time : type of caller
6784+
6785+
Examples
6786+
--------
6787+
>>> i = pd.date_range('2018-04-09', periods=4, freq='4D2min')
6788+
>>> ts = pd.DataFrame({'A': [1,2,3,4]}, index=i)
6789+
>>> ts
6790+
A
6791+
date
6792+
2018-04-09 00:00:00 1
6793+
2018-04-13 00:02:00 2
6794+
2018-04-17 00:04:00 3
6795+
2018-04-21 00:06:00 4
6796+
>>> ts.at_time('0:02')
6797+
A
6798+
date
6799+
2018-04-13 00:02:00 2
6800+
6801+
See Also
6802+
--------
6803+
between_time : Select values between particular times of the day
6804+
first : Select initial periods of time series based on a date offset
6805+
last : Select final periods of time series based on a date offset
67806806
"""
67816807
try:
67826808
indexer = self.index.indexer_at_time(time, asof=asof)
@@ -6789,6 +6815,10 @@ def between_time(self, start_time, end_time, include_start=True,
67896815
"""
67906816
Select values between particular times of the day (e.g., 9:00-9:30 AM).
67916817
6818+
Notes
6819+
-----
6820+
For this method to work, the index must to be a :class:`DatetimeIndex`
6821+
67926822
Parameters
67936823
----------
67946824
start_time : datetime.time or string
@@ -6799,6 +6829,27 @@ def between_time(self, start_time, end_time, include_start=True,
67996829
Returns
68006830
-------
68016831
values_between_time : type of caller
6832+
6833+
Examples
6834+
--------
6835+
>>> i = pd.date_range('2018-04-09', periods=4, freq='2min')
6836+
>>> ts = pd.DataFrame({'A': [1,2,3,4]}, index=i)
6837+
>>> ts
6838+
A
6839+
2018-04-09 00:00:00 1
6840+
2018-04-09 00:02:00 2
6841+
2018-04-09 00:04:00 3
6842+
2018-04-09 00:06:00 4
6843+
>>> ts.between_time('0:02', '0:04')
6844+
A
6845+
2018-04-09 00:02:00 2
6846+
2018-04-09 00:04:00 3
6847+
6848+
See Also
6849+
--------
6850+
at_time : Select values at a particular time of the day
6851+
first : Select initial periods of time series based on a date offset
6852+
last : Select final periods of time series based on a date offset
68026853
"""
68036854
try:
68046855
indexer = self.index.indexer_between_time(
@@ -7052,17 +7103,39 @@ def first(self, offset):
70527103
Convenience method for subsetting initial periods of time series data
70537104
based on a date offset.
70547105
7106+
Notes
7107+
-----
7108+
For this method to work, the index must to be a :class:`DatetimeIndex`
7109+
70557110
Parameters
70567111
----------
70577112
offset : string, DateOffset, dateutil.relativedelta
70587113
70597114
Examples
70607115
--------
7061-
ts.first('10D') -> First 10 days
7116+
>>> i = pd.date_range('2018-04-09', periods=4, freq='D')
7117+
>>> ts = pd.DataFrame({'A': [1,2,3,4]}, index=i)
7118+
>>> ts
7119+
A
7120+
2018-04-09 1
7121+
2018-04-10 2
7122+
2018-04-11 3
7123+
2018-04-12 4
7124+
>>> ts.first('3D')
7125+
A
7126+
2018-04-09 1
7127+
2018-04-10 2
7128+
2018-04-11 3
70627129
70637130
Returns
70647131
-------
70657132
subset : type of caller
7133+
7134+
See Also
7135+
--------
7136+
last : Select final periods of time series based on a date offset
7137+
at_time : Select values at a particular time of the day
7138+
between_time : Select values between particular times of the day
70667139
"""
70677140
from pandas.tseries.frequencies import to_offset
70687141
if not isinstance(self.index, DatetimeIndex):
@@ -7088,17 +7161,39 @@ def last(self, offset):
70887161
Convenience method for subsetting final periods of time series data
70897162
based on a date offset.
70907163
7164+
Notes
7165+
-----
7166+
For this method to work, the index must to be a :class:`DatetimeIndex`
7167+
70917168
Parameters
70927169
----------
70937170
offset : string, DateOffset, dateutil.relativedelta
70947171
70957172
Examples
70967173
--------
7097-
ts.last('5M') -> Last 5 months
7174+
>>> i = pd.date_range('2018-04-09', periods=4, freq='D')
7175+
>>> ts = pd.DataFrame({'A': [1,2,3,4]}, index=i)
7176+
>>> ts
7177+
A
7178+
2018-04-09 1
7179+
2018-04-10 2
7180+
2018-04-11 3
7181+
2018-04-12 4
7182+
>>> ts.last('3D')
7183+
A
7184+
2018-04-10 2
7185+
2018-04-11 3
7186+
2018-04-12 4
70987187
70997188
Returns
71007189
-------
71017190
subset : type of caller
7191+
7192+
See Also
7193+
--------
7194+
first : Select initial periods of time series based on a date offset
7195+
at_time : Select values at a particular time of the day
7196+
between_time : Select values between particular times of the day
71027197
"""
71037198
from pandas.tseries.frequencies import to_offset
71047199
if not isinstance(self.index, DatetimeIndex):

0 commit comments

Comments
 (0)