Pandas 係列是帶有軸標簽的一維ndarray。標簽不必是唯一的,但必須是可哈希的類型。該對象同時支持基於整數和基於標簽的索引,並提供了許多方法來執行涉及索引的操作。
Pandas Series.between_time()
函數選擇一天中特定時間(例如9:00-9:30 AM)之間的值。通過將start_time設置為晚於end_time,您可以獲得的時間不在兩次之間。
用法: Series.between_time(start_time, end_time, include_start=True, include_end=True, axis=None)
參數:
start_time:datetime.time或字符串
end_time:datetime.time或字符串
include_start:布爾值,默認為True
include_end:布爾值,默認為True
axis:{0或“索引”,1或“列”},默認0
返回:values_between_time:與調用者類型相同
範例1:采用Series.between_time()
函數返回給定持續時間內的值。
# importing pandas as pd
import pandas as pd
# Creating the Series
sr = pd.Series([11, 21, 8, 18, 65, 18, 32, 10, 5, 32, None])
# Create the Index
index_ = pd.date_range('2010-10-09 08:45', periods = 11, freq ='H')
# set the index
sr.index = index_
# Print the series
print(sr)
輸出:
現在我們將使用Series.between_time()
函數返回給定持續時間內的值。
# return values between the passed time duration
result = sr.between_time(start_time = '10:45', end_time = '15:45')
# Print the result
print(result)
輸出:
正如我們在輸出中看到的,Series.between_time()
函數已成功返回給定持續時間內的值。
範例2:采用Series.between_time()
函數返回給定持續時間內的值。跳過與開始時間和結束時間相對應的值。
# importing pandas as pd
import pandas as pd
# Creating the Series
sr = pd.Series([11, 21, 8, 18, 65, 18, 32, 10, 5, 32, None])
# Create the Index
index_ = pd.date_range('2010-10-09 08:45', periods = 11, freq ='H')
# set the index
sr.index = index_
# Print the series
print(sr)
輸出:
現在我們將使用Series.between_time()
函數返回給定持續時間內的值。跳過與開始時間和結束時間相對應的值。
# return values between the passed time duration
# skip the start and end time
result = sr.between_time(start_time = '10:45', end_time = '15:45',
include_start = False, include_end = False)
# Print the result
print(result)
輸出:
正如我們在輸出中看到的,Series.between_time()
函數已成功返回給定持續時間內的值。請注意,尚未包括與開始時間和結束時間相對應的值。
相關用法
- Python pandas.map()用法及代碼示例
- Python Pandas Timestamp.now用法及代碼示例
- Python Pandas Timestamp.second用法及代碼示例
- Python Pandas DataFrame.abs()用法及代碼示例
- Python Pandas Series.lt()用法及代碼示例
- Python Pandas dataframe.all()用法及代碼示例
- Python Pandas DataFrame.ix[ ]用法及代碼示例
- Python Pandas Series.pop()用法及代碼示例
- Python Pandas TimedeltaIndex.max用法及代碼示例
- Python Pandas Timestamp.dst用法及代碼示例
- Python Pandas Timestamp.tz用法及代碼示例
- Python Pandas Series.mean()用法及代碼示例
- Python Pandas TimedeltaIndex.min用法及代碼示例
- Python Pandas Series.ptp()用法及代碼示例
- Python Pandas dataframe.cov()用法及代碼示例
注:本文由純淨天空篩選整理自Shubham__Ranjan大神的英文原創作品 Python | Pandas Series.between_time()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。