Python是進行數據分析的一種出色語言,主要是因為以數據為中心的python軟件包具有奇妙的生態係統。 Pandas是其中的一種,使導入和分析數據更加容易。
Pandas Index.argmax()
函數返回輸入索引中存在的最大值的索引。如果我們有多個以上的最大值(即存在多次以上的最大值),則它將返回第一次出現的最大值的索引。
用法: Index.argmax(axis=None)
參數:不帶任何參數。
範例1:采用Index.argmax()
函數查找給定索引中存在的最大值的索引。
# importing pandas as pd
import pandas as pd
# Creating the Index
df = pd.Index([17, 69, 33, 5, 0, 74, 0])
# Print the Index
df
輸出:
讓我們找到索引中存在的最大值的索引。
# function to return the index
# of the maximum value.
df.argmax()
輸出:
5
正如我們在輸出中看到的那樣,Index中的最大值是74,其索引是5,所以輸出是5。
範例2:采用Index.argmax()
函數,當我們多次重複獲得最大值時,找到最大值的索引。
# importing pandas as pd
import pandas as pd
# Creating the Index
df = pd.Index([44, 69, 133, 5, 0, 74, 133])
# Print the Index
df
輸出:
讓我們找到最大值的索引。
# We call the argmax() function to
# find the index of maximum value.
df.argmax()
輸出:
2
正如我們在輸出中看到的,Index.argmax()
函數已返回第一次出現的最大值的索引。
相關用法
- Python pandas.map()用法及代碼示例
- Python Pandas Timestamp.tz用法及代碼示例
- Python Pandas Series.str.contains()用法及代碼示例
- Python Pandas dataframe.std()用法及代碼示例
- Python Pandas Timestamp.dst用法及代碼示例
- Python Pandas dataframe.sem()用法及代碼示例
- Python Pandas DataFrame.ix[ ]用法及代碼示例
- Python Pandas.Categorical()用法及代碼示例
- Python Pandas.apply()用法及代碼示例
- Python Pandas TimedeltaIndex.contains用法及代碼示例
- Python Pandas Timestamp.now用法及代碼示例
- Python Pandas Series.str.pad()用法及代碼示例
- Python Pandas Series.take()用法及代碼示例
- Python Pandas dataframe.all()用法及代碼示例
- Python Pandas series.str.get()用法及代碼示例
注:本文由純淨天空篩選整理自Shubham__Ranjan大神的英文原創作品 Python | Pandas Index.argmax()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。