Để kiểm tra xem một phần tử có thuộc Khoảng thời gian hay không, hãy sử dụng thuộc tính in. Đầu tiên, hãy nhập các thư viện được yêu cầu -
import pandas as pd
Tạo khoảng thời gian
interval = pd.Interval(left=0, right=10)
Hiển thị khoảng thời gian
print("Interval...\n",interval) Kiểm tra sự tồn tại của một phần tử trong Khoảng thời gian
print("\nThe specific element exists in the Interval? = \n",6 in interval)
Ví dụ
Sau đây là mã
import pandas as pd
# Create a time interval
interval = pd.Interval(left=0, right=10)
# display the interval
print("Interval...\n",interval)
# display the interval length
print("\nInterval length...\n",interval.length)
# check for the existence of an element in an Interval
print("\nThe specific element exists in the Interval? = \n",6 in interval) Đầu ra
Điều này sẽ tạo ra mã sau
Interval... (0, 10] Interval length... 10 The specific element exists in the Interval? = True