Python | Панды Index.argmax ()
Python - отличный язык для анализа данных, в первую очередь из-за фантастической экосистемы пакетов Python, ориентированных на данные. Pandas - один из таких пакетов, который значительно упрощает импорт и анализ данных.
Pandas Index.argmax() function returns the indices of the maximum value present in the input Index. If we are having more than one maximum value (i.e. maximum value is present more than once) then it returns the index of the first occurrence of the maximum value.
Syntax: Index.argmax(axis=None)
Parameter: Doesn’t take any parameter.
Example #1: Use Index.argmax() function to find the index of the maximum value present in the given Index.
# importing pandas as pdimport pandas as pd # Creating the Indexdf = pd.Index([17, 69, 33, 5, 0, 74, 0]) # Print the Indexdf |
Выход :
Let’s find the index of the maximum value present in our Index.
# function to return the index # of the maximum value.df.argmax() |
Выход :
5
As we can see in the output, The maximum value in the Index is 74 and its index is 5 so the output is 5.
Example #2: Use Index.argmax() function to find the index of the maximum value when we are having maximum value repeated more than once.
# importing pandas as pdimport pandas as pd # Creating the Indexdf = pd.Index([44, 69, 133, 5, 0, 74, 133]) # Print the Indexdf |
Выход :
Let’s find the index of the maximum value.
# We call the argmax() function to # find the index of maximum value.df.argmax() |
Выход :
2
As we can see in the output, The Index.argmax() function has returned the index of the first occurrence of the maximum value.
Внимание компьютерщик! Укрепите свои основы с помощью базового курса программирования Python и изучите основы.
Для начала подготовьтесь к собеседованию. Расширьте свои концепции структур данных с помощью курса Python DS. А чтобы начать свое путешествие по машинному обучению, присоединяйтесь к курсу Машинное обучение - базовый уровень.