📜  Python|熊猫索引.argmin()

📅  最后修改于: 2022-05-13 01:54:54.901000             🧑  作者: Mango

Python|熊猫索引.argmin()

Python是一种用于进行数据分析的出色语言,主要是因为以数据为中心的Python包的奇妙生态系统。 Pandas就是其中之一,它使导入和分析数据变得更加容易。

Pandas Index.argmin()函数返回输入索引中存在的最小值的索引。如果我们有多个最小值(即最小值出现不止一次),则它返回最小值第一次出现的索引。

示例 #1:使用Index.argmin()函数查找给定索引中存在的最小值的索引。

# importing pandas as pd
import pandas as pd
  
# Creating the Index
df = pd.Index([17, 69, 33, 5, 0, 74, 10])
  
# Print the Index
df

输出 :

让我们找到索引中存在的最小值的索引。

# function to return the index of the minimum value.
df.argmin()

输出 :

4

正如我们在输出中看到的那样,索引中的最小值为 0,其索引为 4,因此输出为 4。示例 #2:当最小值重复多次时,使用Index.argmin()函数查找最小值的索引。

# importing pandas as pd
import pandas as pd
  
# Creating the Index
df = pd.Index([17, 69, 33, 5, 10, 74, 10, 5])
  
# Print the Index
df

输出 :

让我们找到最小值的索引。

# We call the argmin() function to find the index of minimum value.
df.argmin()

输出 :

3