주어진 레이블에 해당하는 올바른 슬라이스 경계를 계산하려면 index.get_slice_bound()를 사용하세요. . 측면 설정 매개변수를 오른쪽으로 .
먼저 필요한 라이브러리를 가져옵니다 -
import pandas as pd
판다 인덱스 생성 -
index = pd.Index([10, 20, 30, 40, 50, 60, 70])
판다 인덱스 표시 -
print("Pandas Index...\n",index) 올바른 슬라이스 바인딩을 가져옵니다. "side" 매개변수가 "right"로 설정된 경우 지정된 레이블의 오른쪽 슬라이스 경계를 반환합니다. -
print("\nGet the right slice bound...\n",index.get_slice_bound(30, side='right', kind ='getitem'))
예시
다음은 코드입니다 -
import pandas as pd
# Creating Pandas index
index = pd.Index([10, 20, 30, 40, 50, 60, 70])
# Display the Pandas index
print("Pandas Index...\n",index)
# Return the number of elements in the Index
print("\nNumber of elements in the index...\n",index.size)
# Get the right slice bound
# Returns the right slice bound of given label if "side" parameter is set to "right"
print("\nGet the right slice bound...\n", index.get_slice_bound(30, side='right', kind ='getitem')) 출력
이것은 다음과 같은 출력을 생성합니다 -
Pandas Index... Int64Index([10, 20, 30, 40, 50, 60, 70], dtype='int64') Number of elements in the index... 7 Get the right slice bound... 3