Python | Серия панд.between_time ()
Серия Pandas - это одномерный массив ndarray с метками осей. Этикетки не обязательно должны быть уникальными, но должны быть хешируемого типа. Объект поддерживает индексирование как на основе целых чисел, так и на основе меток и предоставляет множество методов для выполнения операций, связанных с индексом.
Pandas Series.between_time() function select 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.
Syntax: Series.between_time(start_time, end_time, include_start=True, include_end=True, axis=None)
Parameter :
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 0Returns : values_between_time : same type as caller
Example #1: Use Series.between_time() function to return the values lying in the given time duration.
# importing pandas as pdimport pandas as pd # Creating the Seriessr = pd.Series([11, 21, 8, 18, 65, 18, 32, 10, 5, 32, None]) # Create the Indexindex_ = pd.date_range("2010-10-09 08:45", periods = 11, freq ="H") # set the indexsr.index = index_ # Print the seriesprint(sr) |
Выход :
Now we will use Series.between_time() function to return the values lying in the given time duration.
# return values between the passed time durationresult = sr.between_time(start_time = "10:45", end_time = "15:45") # Print the resultprint(result) |
Output :
As we can see in the output, the Series.between_time() function has successfully returned the values lying in the given time duration.
Example #2 : Use Series.between_time() function to return the values lying in the given time duration. Skip the values corresponding to the start and end time.
# importing pandas as pdimport pandas as pd # Creating the Seriessr = pd.Series([11, 21, 8, 18, 65, 18, 32, 10, 5, 32, None]) # Create the Indexindex_ = pd.date_range("2010-10-09 08:45", periods = 11, freq ="H") # set the indexsr.index = index_ # Print the seriesprint(sr) |
Выход :
Now we will use Series.between_time() function to return the values lying in the given time duration. Skip the values corresponding to the start and end time.
# return values between the passed time duration# skip the start and end timeresult = sr.between_time(start_time = "10:45", end_time = "15:45", include_start = False, include_end = False) # Print the resultprint(result) |
Output :
As we can see in the output, the Series.between_time() function has successfully returned the values lying in the given time duration. Notice the values corresponding to the start and end time has not been included.
Внимание компьютерщик! Укрепите свои основы с помощью базового курса программирования Python и изучите основы.
Для начала подготовьтесь к собеседованию. Расширьте свои концепции структур данных с помощью курса Python DS. А чтобы начать свое путешествие по машинному обучению, присоединяйтесь к курсу Машинное обучение - базовый уровень.