pandas.DatetimeIndex.indexer_between_time#

DatetimeIndex.indexer_between_time(
start_time,
end_time,
include_start=<no_default>,
include_end=<no_default>,
*,
inclusive=<no_default>,
)[source]#

Return index locations of values between particular times of day.

This method returns the integer indices of the DatetimeIndex entries whose time-of-day components fall within the specified range.

Parameters:
start_time, end_timedatetime.time, str

Time passed either as object (datetime.time) or as string in appropriate format (“%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 boundaries; whether to set start bound as closed or open.

Deprecated since version 3.2.0: Use inclusive instead.

include_endbool, default True

Include boundaries; whether to set end bound as closed or open.

Deprecated since version 3.2.0: Use inclusive instead.

inclusive{“both”, “neither”, “left”, “right”}, default “both”

Include boundaries; whether to set each bound as closed or open.

Added in version 3.2.0.

Returns:
np.ndarray[np.intp]

Index locations of values between particular times of day.

See also

indexer_at_time

Get index locations of values at particular time of day.

DataFrame.between_time

Select values between particular times of day.

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[us]', freq='h')
>>> idx.indexer_between_time("00:00", "2:00", inclusive="left")
array([0, 1])