pandas.DatetimeIndex.indexer_between_time#

DatetimeIndex.indexer_between_time(start_time, end_time, include_start=True, include_end=True)[源代码]#

返回一天中特定时间段内的值的索引位置。

Parameters:
start_time, end_timedatetime.time, str

时间,可以作为对象 (datetime.time) 或字符串(格式为 “%H:%M”, “%H%M”, “%I:%M%p”, “%I%M%p”, “%H:%M:%S”, “%H%M%S”, “%I:%M:%S%p”,”%I%M%S%p”)传入。

include_startbool, default True
include_endbool, default True
Returns:
np.ndarray[np.intp]

参见

indexer_at_time

获取一天中特定时间的值的索引位置。

DataFrame.between_time

选择一天中特定时间段中的值。

Examples

>>> idx = pd.date_range("2023-01-01", periods=4, freq="h")
>>> idx
DatetimeIndex(['2023-01-01 00:00:00', '2023-01-01 01:00:00',
                   '2023-01-01 02:00:00', '2023-01-01 03:00:00'],
                  dtype='datetime64[ns]', freq='h')
>>> idx.indexer_between_time("00:00", "2:00", include_end=False)
array([0, 1])