Để kiểm tra xem Khoảng thời gian có được đóng ở phía bên trái hay không, hãy sử dụng khoảng thời gian.closed_right bất động sản. Đầu tiên, hãy nhập các thư viện được yêu cầu -
import pandas as pd
Tập hợp khoảng thời gian sử dụng tham số "đóng" với giá trị "phải", tức là [0, 5) được mô tả bằng 0
interval = pd.Interval(left=0, right=20, closed='right')
Hiển thị khoảng thời gian
print("Interval...\n",interval)
Kiểm tra xem khoảng thời gian có được đóng ở phía bên phải hay không
print("\nChecking whether the Interval is closed on the right...\n", interval.closed_right)
Ví dụ
Sau đây là mã
import pandas as pd # Interval set using the "closed" parameter with value "right" # i.e. [0, 5) is described by 0 < x <= 5 when closed='right' interval = pd.Interval(left=0, right=20, closed='right') # display the interval print("Interval...\n",interval) # display the interval length print("\nInterval length...\n",interval.length) # check whether the interval is closed on the right-side print("\nChecking whether the Interval is closed on the right...\n", interval.closed_right) # check for the existence of an element in an Interval # This shows that closed = right contain only the right-most endpoint print("\nThe left-most element exists in the Interval? = \n",0 in interval) print("\nThe right-most element exists in the Interval? = \n",20 in interval)
Đầu ra
Điều này sẽ tạo ra mã sau
Interval... (0, 20] Interval length... 20 Checking whether the Interval is closed on the right... True