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