pandas.DataFrame.between_time() Function with example

Spread the love

pandas.DataFrame.between_time: This function returns select values between particular times of the day (e.g., 9:00-9:30 AM).

Syntax: DataFrame.between_time(start_time, end_time, include_start=True, include_end=True, axis=None)

By setting start_time to be later than end_time, you can get the times that are not between the two times.

Parameters:
start_time : datetime.time or string
end_time : datetime.time or string
include_start : boolean, default True
include_end : boolean, default True
axis : {0 or ‘index’, 1 or ‘columns’}, default 0

Returns:
values_between_time : same type as caller
Raises:
TypeError
If the index is not a DatetimeIndex

#example program on pandas.DataFrame.between_time() Function

import pandas as pd i = pd.date_range('2019-03-20', periods=4, freq='12H') ts = pd.DataFrame({'A': [1,2,3,4]}, index=i) print(ts) print(ts.between_time('12:00', '13:00'))

Output:

                     A
2019-03-20 00:00:00  1
2019-03-20 12:00:00  2
2019-03-21 00:00:00  3
2019-03-21 12:00:00  4
                     A
2019-03-20 12:00:00  2
2019-03-21 12:00:00  4

 

admin

admin

Leave a Reply

Your email address will not be published. Required fields are marked *