pandas.Series.between_time#

Series.between_time(start_time, end_time, inclusive='both', axis=None)[源代码]#

选择一天中特定时间段内的(例如,上午 9:00-9:30)值。

通过将 start_time 设置为晚于 end_time,您可以获取*不*在这两个时间之间的时段。

Parameters:
start_timedatetime.time 或 str

作为时间过滤器限制的初始时间。

end_timedatetime.time 或 str

作为时间过滤器限制的结束时间。

inclusive{“both”, “neither”, “left”, “right”},默认为 “both”

是否包含边界;设置每个边界是闭合的还是开放的。

axis{0 或 ‘index’, 1 或 ‘columns’}, default 0

根据索引或列值确定范围时间。对于 Series,此参数未使用,默认为 0。

Returns:
Series 或 DataFrame

从原始对象中筛选到指定日期范围的数据。

Raises:
TypeError

如果索引不是 DatetimeIndex

参见

at_time

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

first

根据日期偏移量选择时间序列的初始周期。

last

根据日期偏移量选择时间序列的最终周期。

DatetimeIndex.indexer_between_time

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

Examples

>>> i = pd.date_range('2018-04-09', periods=4, freq='1D20min')
>>> ts = pd.DataFrame({'A': [1, 2, 3, 4]}, index=i)
>>> ts
                     A
2018-04-09 00:00:00  1
2018-04-10 00:20:00  2
2018-04-11 00:40:00  3
2018-04-12 01:00:00  4
>>> ts.between_time('0:15', '0:45')
                     A
2018-04-10 00:20:00  2
2018-04-11 00:40:00  3

通过将 start_time 设置为晚于 end_time,您可以获取*不*在这两个时间之间的时段:

>>> ts.between_time('0:45', '0:15')
                     A
2018-04-09 00:00:00  1
2018-04-12 01:00:00  4