หากต้องการตรวจสอบว่าองค์ประกอบเป็นของ Interval หรือไม่ ให้ใช้คุณสมบัติ in ขั้นแรก นำเข้าไลบรารีที่จำเป็น -
import pandas as pd
สร้างช่วงเวลา
interval = pd.Interval(left=0, right=10)
แสดงช่วงเวลา
print("Interval...\n",interval) ตรวจสอบการมีอยู่ขององค์ประกอบในช่วงเวลา
print("\nThe specific element exists in the Interval? = \n",6 in interval)
ตัวอย่าง
ต่อไปนี้เป็นรหัส
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) ผลลัพธ์
ซึ่งจะได้รหัสดังต่อไปนี้
Interval... (0, 10] Interval length... 10 The specific element exists in the Interval? = True