현재와 동일하지만 지정된 쪽에서 닫힌 IntervalArray를 반환하려면 set_closed()를 사용하세요. 매개변수가 both로 설정된 메소드 .
먼저 필요한 라이브러리를 가져옵니다 -
import pandas as pd
간격배열 생성 -
index = pd.arrays.IntervalArray.from_breaks(range(6))
간격 표시 -
print("IntervalIndex...\n",index) 현재 것과 동일하지만 지정된 쪽에서 닫혀 있는 IntervalArray를 반환합니다. 즉, "둘 다" 여기 −
print("\nResult...",index.set_closed('both'))
예시
다음은 코드입니다 -
import pandas as pd
# Create IntervalArray
index = pd.arrays.IntervalArray.from_breaks(range(6))
# 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. "both" here
print("\nResult...",index.set_closed('both')) 출력
이것은 다음과 같은 출력을 생성합니다 -
IntervalIndex... <IntervalArray> [(0, 1], (1, 2], (2, 3], (3, 4], (4, 5]] Length: 5, dtype: interval[int64, right] IntervalIndex length... Int64Index([1, 1, 1, 1, 1], dtype='int64') The left bound for the IntervalIndex... Int64Index([0, 1, 2, 3, 4], dtype='int64') The right bound for the IntervalIndex... Int64Index([1, 2, 3, 4, 5], dtype='int64') Result... <IntervalArray> [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]] Length: 5, dtype: interval[int64, both]