@@ -6703,9 +6703,10 @@ def at_time(self, time, asof=False):
6703
6703
"""
6704
6704
Select values at particular time of day (e.g. 9:30AM).
6705
6705
6706
- Notes
6706
+ Raises
6707
6707
-----
6708
- For this method to work, the index must to be a :class:`DatetimeIndex`
6708
+ AttributeError
6709
+ If the index is not a :class:`DatetimeIndex`
6709
6710
6710
6711
Parameters
6711
6712
----------
@@ -6717,25 +6718,27 @@ def at_time(self, time, asof=False):
6717
6718
6718
6719
Examples
6719
6720
--------
6720
- >>> i = pd.date_range('2018-04-09', periods=4, freq='4D2min ')
6721
+ >>> i = pd.date_range('2018-04-09', periods=4, freq='12H ')
6721
6722
>>> ts = pd.DataFrame({'A': [1,2,3,4]}, index=i)
6722
6723
>>> ts
6723
6724
A
6724
- date
6725
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')
6726
+ 2018-04-09 12:00:00 2
6727
+ 2018-04-10 00:00:00 3
6728
+ 2018-04-10 12:00:00 4
6729
+
6730
+ >>> ts.at_time('12:00')
6730
6731
A
6731
- date
6732
- 2018-04-13 00:02: 00 2
6732
+ 2018-04-09 12:00:00 2
6733
+ 2018-04-10 12: 00:00 4
6733
6734
6734
6735
See Also
6735
6736
--------
6736
6737
between_time : Select values between particular times of the day
6737
6738
first : Select initial periods of time series based on a date offset
6738
6739
last : Select final periods of time series based on a date offset
6740
+ DatetimeIndex.indexer_at_time : Get just the index positions for
6741
+ values at particular time of the day
6739
6742
"""
6740
6743
try :
6741
6744
indexer = self .index .indexer_at_time (time , asof = asof )
@@ -6748,9 +6751,13 @@ def between_time(self, start_time, end_time, include_start=True,
6748
6751
"""
6749
6752
Select values between particular times of the day (e.g., 9:00-9:30 AM).
6750
6753
6751
- Notes
6754
+ By setting ``start_time`` to be later than ``end_time``,
6755
+ you can get the times that are *not* between the two times.
6756
+
6757
+ Raises
6752
6758
-----
6753
- For this method to work, the index must to be a :class:`DatetimeIndex`
6759
+ AttributeError
6760
+ If the index is not a :class:`DatetimeIndex`
6754
6761
6755
6762
Parameters
6756
6763
----------
@@ -6765,24 +6772,35 @@ def between_time(self, start_time, end_time, include_start=True,
6765
6772
6766
6773
Examples
6767
6774
--------
6768
- >>> i = pd.date_range('2018-04-09', periods=4, freq='2min ')
6775
+ >>> i = pd.date_range('2018-04-09', periods=4, freq='1D20min ')
6769
6776
>>> ts = pd.DataFrame({'A': [1,2,3,4]}, index=i)
6770
6777
>>> ts
6771
6778
A
6772
6779
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')
6780
+ 2018-04-10 00:20:00 2
6781
+ 2018-04-11 00:40:00 3
6782
+ 2018-04-12 01:00:00 4
6783
+
6784
+ >>> ts.between_time('0:15', '0:45')
6777
6785
A
6778
- 2018-04-09 00:02:00 2
6779
- 2018-04-09 00:04:00 3
6786
+ 2018-04-10 00:20:00 2
6787
+ 2018-04-11 00:40:00 3
6788
+
6789
+ You get the times that are *not* between two times by setting
6790
+ ``start_time`` later than ``end_time``:
6791
+
6792
+ >>> ts.between_time('0:45', '0:15')
6793
+ A
6794
+ 2018-04-09 00:00:00 1
6795
+ 2018-04-12 01:00:00 4
6780
6796
6781
6797
See Also
6782
6798
--------
6783
6799
at_time : Select values at a particular time of the day
6784
6800
first : Select initial periods of time series based on a date offset
6785
6801
last : Select final periods of time series based on a date offset
6802
+ DatetimeIndex.indexer_between_time : Get just the index positions for
6803
+ values between particular times of the day
6786
6804
"""
6787
6805
try :
6788
6806
indexer = self .index .indexer_between_time (
@@ -7036,29 +7054,36 @@ def first(self, offset):
7036
7054
Convenience method for subsetting initial periods of time series data
7037
7055
based on a date offset.
7038
7056
7039
- Notes
7057
+ Raises
7040
7058
-----
7041
- For this method to work, the index must to be a :class:`DatetimeIndex`
7059
+ NotImplementedError
7060
+ If the index is not a :class:`DatetimeIndex`
7042
7061
7043
7062
Parameters
7044
7063
----------
7045
7064
offset : string, DateOffset, dateutil.relativedelta
7046
7065
7047
7066
Examples
7048
7067
--------
7049
- >>> i = pd.date_range('2018-04-09', periods=4, freq='D ')
7068
+ >>> i = pd.date_range('2018-04-09', periods=4, freq='2D ')
7050
7069
>>> ts = pd.DataFrame({'A': [1,2,3,4]}, index=i)
7051
7070
>>> ts
7052
7071
A
7053
7072
2018-04-09 1
7054
- 2018-04-10 2
7055
- 2018-04-11 3
7056
- 2018-04-12 4
7073
+ 2018-04-11 2
7074
+ 2018-04-13 3
7075
+ 2018-04-15 4
7076
+
7077
+ Get the rows for the first 3 days:
7078
+
7057
7079
>>> ts.first('3D')
7058
7080
A
7059
7081
2018-04-09 1
7060
- 2018-04-10 2
7061
- 2018-04-11 3
7082
+ 2018-04-11 2
7083
+
7084
+ Notice the data for 3 first calender days were returned, not the first
7085
+ 3 days observed in the dataset, and therefore data for 2018-04-13 was
7086
+ not returned.
7062
7087
7063
7088
Returns
7064
7089
-------
@@ -7094,29 +7119,36 @@ def last(self, offset):
7094
7119
Convenience method for subsetting final periods of time series data
7095
7120
based on a date offset.
7096
7121
7097
- Notes
7122
+ Raises
7098
7123
-----
7099
- For this method to work, the index must to be a :class:`DatetimeIndex`
7124
+ NotImplementedError
7125
+ If the index is not a :class:`DatetimeIndex`
7100
7126
7101
7127
Parameters
7102
7128
----------
7103
7129
offset : string, DateOffset, dateutil.relativedelta
7104
7130
7105
7131
Examples
7106
7132
--------
7107
- >>> i = pd.date_range('2018-04-09', periods=4, freq='D ')
7133
+ >>> i = pd.date_range('2018-04-09', periods=4, freq='2D ')
7108
7134
>>> ts = pd.DataFrame({'A': [1,2,3,4]}, index=i)
7109
7135
>>> ts
7110
7136
A
7111
7137
2018-04-09 1
7112
- 2018-04-10 2
7113
- 2018-04-11 3
7114
- 2018-04-12 4
7138
+ 2018-04-11 2
7139
+ 2018-04-13 3
7140
+ 2018-04-15 4
7141
+
7142
+ Get the rows for the last 3 days:
7143
+
7115
7144
>>> ts.last('3D')
7116
7145
A
7117
- 2018-04-10 2
7118
- 2018-04-11 3
7119
- 2018-04-12 4
7146
+ 2018-04-13 3
7147
+ 2018-04-15 4
7148
+
7149
+ Notice the data for 3 last calender days were returned, not the last
7150
+ 3 observed days in the dataset. and therefore data for 2018-04-13 was
7151
+ not returned.
7120
7152
7121
7153
Returns
7122
7154
-------
0 commit comments