倉庫指標
- Star
- (6,000 star)
- PR 合併指標
- (平均合併 17天 21小時) (30 天內合併 230 個 PR)
描述
For pandas API compatibility, we can implement Series and DataFrame.between_time. between_time "select[s] values between particular times of the day (e.g., 9:00-9:30 AM). By setting start_time to be later than end_time, you can get the times that are not between the two times."
If the index is not a DatetimeIndex, this method throws a TypeError. DateTimes without time components are considered as if the time component were "0:00:00". Valid {start, end}_time must be in the interval [0:00 and 24:00).
The API documentation does not indicate what resolutions are valid or invalid for {start, end}_time, but it is documented as only including granularity down to seconds in the utility function:
Return index locations of values between particular times of day
(e.g., 9:00-9:30AM).
Parameters
----------
start_time, end_time : datetime.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_start : bool, default True
include_end : bool, default True
import pandas as pd
i = pd.date_range('2018-04-09', periods=4, freq='1D20min')
ts = pd.DataFrame({'A': [1, 2, 3, 4]}, index=i)
print(ts)
print(ts.between_time('0:15', '0:45'))
print(ts.between_time('0:45', '0:15'))
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
A
2018-04-10 00:20:00 2
2018-04-11 00:40:00 3
A
2018-04-09 00:00:00 1
2018-04-12 01:00:00 4
i = pd.Series(["2021-01-01", "2021-02-10"], dtype="datetime64[ns]")
s = pd.Series([0,1], index=i)
print(s, "\n")
print(s.between_time("0:00:01", "23:59:59"), "\n")
print(s.between_time("0:00", "0:15"))
2021-01-01 0
2021-02-10 1
dtype: int64
Series([], dtype: int64)
2021-01-01 0
2021-02-10 1
dtype: int64