Select values at particular time of day (e.g., 9:30AM). Parameters ---------- time : datetime.time or str The values to select. asof : bool, default False This parameter is currently not supported. axis : {0 or 'index', 1 or '
(self, time, asof: bool = False, axis: Axis | None = None)
| 8897 | |
| 8898 | @final |
| 8899 | def at_time(self, time, asof: bool = False, axis: Axis | None = None) -> Self: |
| 8900 | """ |
| 8901 | Select values at particular time of day (e.g., 9:30AM). |
| 8902 | |
| 8903 | Parameters |
| 8904 | ---------- |
| 8905 | time : datetime.time or str |
| 8906 | The values to select. |
| 8907 | asof : bool, default False |
| 8908 | This parameter is currently not supported. |
| 8909 | axis : {0 or 'index', 1 or 'columns'}, default 0 |
| 8910 | For `Series` this parameter is unused and defaults to 0. |
| 8911 | |
| 8912 | Returns |
| 8913 | ------- |
| 8914 | Series or DataFrame |
| 8915 | The values with the specified time. |
| 8916 | |
| 8917 | Raises |
| 8918 | ------ |
| 8919 | TypeError |
| 8920 | If the index is not a :class:`DatetimeIndex` |
| 8921 | |
| 8922 | See Also |
| 8923 | -------- |
| 8924 | between_time : Select values between particular times of the day. |
| 8925 | first : Select initial periods of time series based on a date offset. |
| 8926 | last : Select final periods of time series based on a date offset. |
| 8927 | DatetimeIndex.indexer_at_time : Get just the index locations for |
| 8928 | values at particular time of the day. |
| 8929 | |
| 8930 | Examples |
| 8931 | -------- |
| 8932 | >>> i = pd.date_range("2018-04-09", periods=4, freq="12h") |
| 8933 | >>> ts = pd.DataFrame({"A": [1, 2, 3, 4]}, index=i) |
| 8934 | >>> ts |
| 8935 | A |
| 8936 | 2018-04-09 00:00:00 1 |
| 8937 | 2018-04-09 12:00:00 2 |
| 8938 | 2018-04-10 00:00:00 3 |
| 8939 | 2018-04-10 12:00:00 4 |
| 8940 | |
| 8941 | >>> ts.at_time("12:00") |
| 8942 | A |
| 8943 | 2018-04-09 12:00:00 2 |
| 8944 | 2018-04-10 12:00:00 4 |
| 8945 | """ |
| 8946 | if axis is None: |
| 8947 | axis = 0 |
| 8948 | axis = self._get_axis_number(axis) |
| 8949 | |
| 8950 | index = self._get_axis(axis) |
| 8951 | |
| 8952 | if not isinstance(index, DatetimeIndex): |
| 8953 | raise TypeError("Index must be DatetimeIndex") |
| 8954 | |
| 8955 | indexer = index.indexer_at_time(time, asof=asof) |
| 8956 | return self.take(indexer, axis=axis) |