Pandas DataFrame.idxmax() Function
Python Pandas DataFrame.idxmax() function returns the index of the maximum value in a row or column.
pandas.DataFrame.idxmax()
Syntax
DataFrame.idxmax(axis=0, skipna=True)
parameter
axis |
It is a parameter of integer or string type. It specifies the axis to be used. 0 or index represents rows and 1 or columns represents columns. |
skipna |
It is a Boolean parameter. This parameter specifies to exclude null values. If the entire row or column is null, the result will be NA. |
Return Value
It returns an Series
index representing the maximum value along the specified axis.
Example code: DataFrame.idxmax()
Find the maximum numeric index by row
import pandas as pd
dataframe=pd.DataFrame({'Attendance': {0: 60, 1: 100, 2: 80,3: 78,4: 95},
'Obtained Marks': {0: 90, 1: 75, 2: 82, 3: 64, 4: 45}})
print("The Original Data frame is: \n")
print(dataframe)
series = dataframe.idxmax()
print("The Indexes are: \n")
print(series)
Output:
The Original Data frame is:
Attendance Obtained Marks
0 60 90
1 100 75
2 80 82
3 78 64
4 95 45
The Indexes are:
Attendance 1
Obtained Marks 0
dtype: int64
The function returns the index of the maximum Attendance
and Obtained Marks
.
Sample code: DataFrame.idxmax()
Find the maximum value index by column
import pandas as pd
dataframe=pd.DataFrame({'Attendance': {0: 60, 1: 100, 2: 80,3: 78,4: 95},
'Obtained Marks': {0: 90, 1: 75, 2: 82, 3: 64, 4: 45}})
print("The Original Data frame is: \n")
print(dataframe)
series = dataframe.idxmax(axis= 1)
print("The Indexes are: \n")
print(series)
Output:
The Original Data frame is:
Attendance Obtained Marks
0 60 90
1 100 75
2 80 82
3 78 64
4 95 45
The Indexes are:
0 Obtained Marks
1 Attendance
2 Obtained Marks
3 Attendance
4 Attendance
dtype: object
This function returns the index by column.
For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.
Related Articles
Pandas DataFrame.astype() Function
Publish Date:2025/05/01 Views:160 Category:Python
-
Python Pandas DataFrame.astype() function changes the data type of an object to the specified data type. pandas.DataFrame.astype() grammar DataFrame . astype(dtype, copy = True , errors = "raise" ) parameter dtype The data type we want to a
Pandas DataFrame sort_index() Function
Publish Date:2025/05/01 Views:183 Category:Python
-
This tutorial explains how to use pandas.DataFrame.sort_index() the sort method to sort a Pandas DataFrame based on its index. We will use the DataFrame shown in the above example to explain how to sort a Pandas DataFrame based on the index
Pandas cut function
Publish Date:2025/05/01 Views:165 Category:Python
-
pandas.cut() The function can distribute the given data into a range, which can also be called bins . We will use the following DataFrame in this article. import pandas as pd df = pd . DataFrame( { "Name" : [ "Anish" , "Birat" , "Chirag" ,
Appending to an Empty DataFrame in Pandas
Publish Date:2025/05/01 Views:54 Category:Python
-
As we learned earlier, Pandas in Python is an open source module that we can use for data analysis and making machine learning models. It is Numpy used along with another package called as they go hand in hand to support multidimensional ar
Pandas DataFrame DataFrame.query() function
Publish Date:2025/04/30 Views:108 Category:Python
-
The pandas.DataFrame.query() method filters the rows of the caller DataFrame using the given query expression. pandas.DataFrame.query() grammar DataFrame . query(expr, inplace = False , ** kwargs) parameter expr Filter rows based on query e
Pandas DataFrame DataFrame.min() function
Publish Date:2025/04/30 Views:162 Category:Python
-
Python Pandas DataFrame.min() function gets the minimum value of the DataFrame object along the specified axis. pandas.DataFrame.min() grammar DataFrame . mean(axis = None , skipna = None , level = None , numeric_only = None , ** kwargs) pa
Pandas DataFrame DataFrame.mean() function
Publish Date:2025/04/30 Views:86 Category:Python
-
Python Pandas DataFrame.mean() function calculates the mean of the values of the DataFrame object over the specified axis. pandas.DataFrame.mean() grammar DataFrame . mean(axis = None , skipna = None , level = None , numeric_only = No
Pandas DataFrame DataFrame.isin() function
Publish Date:2025/04/30 Views:133 Category:Python
-
The pandas.DataFrame.isin(values) function checks whether each element in the caller DataFrame contains values the value specified in the input . pandas.DataFrame.isin(values) grammar DataFrame . isin(values) parameter values iterable - lis
Pandas DataFrame DataFrame.groupby() function
Publish Date:2025/04/30 Views:161 Category:Python
-
pandas.DataFrame.groupby() takes a DataFrame as input and divides the DataFrame into groups based on a given criterion. We can use groupby() the method to easily process large datasets. pandas.DataFrame.groupby() grammar DataFrame . groupby