닫힌 끝점을 공유하는 두 개의 Interval 개체가 겹치는지 확인하려면 overlaps()를 사용하세요. 방법.
먼저 필요한 라이브러리를 가져옵니다 -
import pandas as pd
닫힌 끝점을 포함하여 공통점을 공유하는 경우 두 간격이 겹칩니다. 열린 끝점만 공통적으로 있는 간격은 겹치지 않습니다.
두 개의 Interval 개체를 만듭니다. 양쪽에서 간격이 닫힙니다. 값이 "both"인 "closed" 매개변수를 사용하여 설정된 간격
interval1 = pd.Interval(10, 30, closed='both') interval2 = pd.Interval(30, 50, closed='both')
간격 표시
print("Interval1...\n",interval1)
print("Interval2...\n",interval2) 두 간격 개체가 겹치는지 확인하십시오.
print("\nDo both the interval objects overlap?\n",interval1.overlaps(interval2)) 예시
다음은 코드입니다.
import pandas as pd
# Two intervals overlap if they share a common point, including closed endpoints
# Intervals that only have an open endpoint in common do not overlap
# Create two Interval objects
# Interval closed from the both sides
# Interval set using the "closed" parameter with value "both"
interval1 = pd.Interval(10, 30, closed='both')
interval2 = pd.Interval(30, 50, closed='both')
# display the intervals
print("Interval1...\n",interval1)
print("Interval2...\n",interval2)
# display the length of both Interval1 and Interval2 objects
print("\nInterval1 object length = ",interval1.length)
print("\nInterval2 object length = ",interval2.length)
# check whether both the interval objects overlap
print("\nDo both the interval objects overlap?\n",interval1.overlaps(interval2)) 출력
그러면 다음 코드가 생성됩니다.
Interval1... [10, 30] Interval2... [30, 50] Interval1 object length = 20 Interval2 object length = 20 Do both the interval objects overlap? True