Computer >> 컴퓨터 >  >> 프로그램 작성 >> Python

Python Pandas - 인덱스에서 가장 작은 값의 int 위치를 반환합니다.

<시간/>

인덱스에서 가장 작은 값의 int 위치를 반환하려면 index.argmin()을 사용하세요. 방법.

먼저 필요한 라이브러리를 가져옵니다 -

import pandas as pd

인덱스 생성 -

index = pd.Index([15, 25, 55, 10, 100, 70, 35, 40, 55])

인덱스 표시 -

print("Pandas Index...\n",index)

인덱스에서 가장 작은 값의 int 위치 가져오기 -

print("\nGet the int position of the smallest value in the Index...\n",index.argmin())

예시

다음은 코드입니다 -

import pandas as pd

# Creating the index
index = pd.Index([15, 25, 55, 10, 100, 70, 35, 40, 55])

# Display the index
print("Pandas Index...\n",index)

# Return a tuple of the shape of the underlying data
print("\nA tuple of the shape of underlying data...\n",index.shape)

# Return the number of elements in the Index
print("\nNumber of elements in the index...\n",index.size)

# The int position of the smallest value in the Index
print("\nGet the int position of the smallest value in the Index...\n",index.argmin())

출력

이것은 다음 코드를 생성합니다 -

Pandas Index...
Int64Index([15, 25, 55, 10, 100, 70, 35, 40, 55], dtype='int64')

A tuple of the shape of underlying data...
(9,)

Number of elements in the index...
9

Get the int position of the smallest value in the Index...
3