분할 배열에서 IntervalArray를 만들려면 pandas.arrays.IntervalArray.from_breaks()를 사용하세요.
간격이 왼쪽 또는 오른쪽, 둘 다 또는 둘 다에서 닫혀 있는지 확인하려면 array.closed 속성을 사용합니다.
먼저 필요한 라이브러리를 가져옵니다 -
import pandas as pd
배열과 유사한 분할에서 새 IntervalArray를 구성합니다. 간격은 기본적으로 "오른쪽"에서 닫힙니다 -
array = pd.arrays.IntervalArray.from_breaks([0, 1, 2, 3, 4, 5])
간격 표시 -
print("Our IntervalArray...\n",array) Interval Array의 간격이 왼쪽, 오른쪽, 둘 다 또는 둘 다에서 닫혀 있는지 확인하십시오. −
print("\nChecking whether the intervals is closed...\n",array.closed)
예시
다음은 코드입니다 -
import pandas as pd
# Construct a new IntervalArray from an array-like of splits
# the intervals are closed on the "right" by default
array = pd.arrays.IntervalArray.from_breaks([0, 1, 2, 3, 4, 5])
# Display the IntervalArray
print("Our IntervalArray...\n",array)
# Getting the length of IntervalArray
# Returns an Index with entries denoting the length of each Interval in the IntervalArray
print("\nOur IntervalArray length...\n",array.length)
# midpoint of each Interval in the IntervalArray as an Index
print("\nThe midpoint of each interval in the IntervalArray...\n",array.mid)
# get the right endpoints
print("\nThe right endpoints of each Interval in the IntervalArray as an Index...\n",array.right)
# check whether the intervals in the Interval Array is closed on the left-side, right-side,
# both or neither
print("\nChecking whether the intervals is closed...\n",array.closed) 출력
이것은 다음 코드를 생성합니다 -
Our IntervalArray... <IntervalArray> [(0, 1], (1, 2], (2, 3], (3, 4], (4, 5]] Length: 5, dtype: interval[int64, right] Our IntervalArray length... Int64Index([1, 1, 1, 1, 1], dtype='int64') The midpoint of each interval in the IntervalArray... Float64Index([0.5, 1.5, 2.5, 3.5, 4.5], dtype='float64') The right endpoints of each Interval in the IntervalArray as an Index... Int64Index([1, 2, 3, 4, 5], dtype='int64') Checking whether the intervals is closed... Right