Python|熊猫系列.argmin()
Pandas 系列是带有轴标签的一维 ndarray。标签不必是唯一的,但必须是可散列的类型。该对象支持基于整数和基于标签的索引,并提供了许多用于执行涉及索引的操作的方法。
Pandas Series.argmin()
函数返回给定系列对象中最小值的行标签。
Syntax: Series.argmin(axis=0, skipna=True, *args, **kwargs)
Parameter :
skipna : Exclude NA/null values. If the entire Series is NA, the result will be NA.
axis : For compatibility with DataFrame.idxmin. Redundant for application on Series.
*args, **kwargs : Additional keywords have no effect but might be accepted for compatibility with NumPy.
Returns : idxmin : Index of minimum of values.
示例 #1:使用Series.argmin()
函数返回给定系列对象中最小值的行标签
# importing pandas as pd
import pandas as pd
# Creating the Series
sr = pd.Series([34, 5, 13, 32, 4, 15])
# Create the Index
index_ = ['Coca Cola', 'Sprite', 'Coke', 'Fanta', 'Dew', 'ThumbsUp']
# set the index
sr.index = index_
# Print the series
print(sr)
输出 :
Coca Cola 34
Sprite 5
Coke 13
Fanta 32
Dew 4
ThumbsUp 15
dtype: int64
现在我们将使用Series.argmin()
函数返回给定系列对象中最小值的行标签。
# return the row label for
# the minimum value
result = sr.argmin()
# Print the result
print(result)
输出 :
Dew
正如我们在输出中看到的, Series.argmin()
函数已成功返回给定系列对象中最小值的行标签。示例 #2:使用Series.argmin()
函数返回给定系列对象中最小值的行标签。
# importing pandas as pd
import pandas as pd
# Creating the Series
sr = pd.Series([11, 21, 8, 18, 65, 18, 32, 10, 5, 32, None])
# Create the Index
# apply yearly frequency
index_ = pd.date_range('2010-10-09 08:45', periods = 11, freq ='Y')
# set the index
sr.index = index_
# Print the series
print(sr)
输出 :
2010-12-31 08:45:00 11.0
2011-12-31 08:45:00 21.0
2012-12-31 08:45:00 8.0
2013-12-31 08:45:00 18.0
2014-12-31 08:45:00 65.0
2015-12-31 08:45:00 18.0
2016-12-31 08:45:00 32.0
2017-12-31 08:45:00 10.0
2018-12-31 08:45:00 5.0
2019-12-31 08:45:00 32.0
2020-12-31 08:45:00 NaN
Freq: A-DEC, dtype: float64
现在我们将使用Series.argmin()
函数返回给定系列对象中最小值的行标签。
# return the row label for
# the minimum value
result = sr.argmin()
# Print the result
print(result)
输出 :
2018-12-31 08:45:00
正如我们在输出中看到的, Series.argmin()
函数已成功返回给定系列对象中最小值的行标签。