현재와 동일하지만 왼쪽이 닫힌 IntervalArray를 반환하려면 set_closed()를 사용하세요. 값이 left인 메소드 .
먼저 필요한 라이브러리를 가져옵니다 -
import pandas as pd
간격배열 생성 -
index = pd.arrays.IntervalArray.from_breaks(range(5))
간격 표시 -
print("IntervalIndex...\n",index) 현재 것과 동일하지만 지정된 쪽에서 닫혀 있는 IntervalArray를 반환합니다. 즉, "왼쪽"이 여기에 있습니다.
print("\nResult...",index.set_closed('left'))
예시
다음은 코드입니다 -
import pandas as pd
# Create IntervalArray
index = pd.arrays.IntervalArray.from_breaks(range(5))
# Display the interval
print("IntervalIndex...\n",index)
# Display the interval length
print("\nIntervalIndex length...\n",index.length)
# the left bound
print("\nThe left bound for the IntervalIndex...\n",index.left)
# the right bound
print("\nThe right bound for the IntervalIndex...\n",index.right)
# Return an IntervalArray identical to the current one but closed on specified
# side i.e. "left" here
print("\nResult...",index.set_closed('left')) 출력
이것은 다음과 같은 출력을 생성합니다 -
IntervalIndex... <IntervalArray> [(0, 1], (1, 2], (2, 3], (3, 4]] Length: 4, dtype: interval[int64, right] IntervalIndex length... Int64Index([1, 1, 1, 1], dtype='int64') The left bound for the IntervalIndex... Int64Index([0, 1, 2, 3], dtype='int64') The right bound for the IntervalIndex... Int64Index([1, 2, 3, 4], dtype='int64') Result... <IntervalArray> [[0, 1), [1, 2), [2, 3), [3, 4)] Length: 4, dtype: interval[int64, left]