DataFrame.idxmin(self, axis=0, skipna=True) [source]
返回在请求轴上第一次出现最小值的索引。不包括NA/null
。
参数: |
默认 行为
排除 则结果为 |
返回值: |
沿指定轴的最小值索引。 |
Raises: |
如果行/列为空 |
Notes
此方法是的DataFrame版本ndarray.argmin
。
例子
1)使用 idxmin() 函数来沿索引轴查找最小值的索引
# importing pandas as pd import pandas as pd # Creating the dataframe df = pd.DataFrame({ "A": [4, 5, 2, 6], "B": [11, 2, 5, 8], "C": [1, 8, 66, 4] }) # Print the dataframe print("DataFrame:") print(df) # Applying idxmin() function along index axis (axis=0) min_index = df.idxmin(axis=0) print("\n最小值的索引:") print(min_index)
2)使用 idxmin() 函数查找沿列轴的最小值的索引
# importing pandas as pd import pandas as pd # Creating the dataframe df = pd.DataFrame({ "A": [4, 5, 2, None], "B": [11, 2, None, 8], "C": [1, 8, 66, 4] }) # Skipna = True will skip all the Na values # find minimum along column axis (axis=1) min_index_column = df.idxmin(axis=1, skipna=True) print("DataFrame with NA values:") print(df) print("\n最小值的索引(沿列轴,跳过NA值):") print(min_index_column)