Pandas DataFrame.idxmax() Function
-
Syntax of
pandas.DataFrame.idxmax()
: -
Example Codes:
DataFrame.idxmax()
Method to Find Indexes of Maximum Values Row-Wise -
Example Codes:
DataFrame.idxmax()
Method to Find Indexes of Maximum Values Column-Wise
Python Pandas DataFrame.idxmax()
function returns the index of the maximum value in rows or columns.
Syntax of pandas.DataFrame.idxmax()
:
DataFrame.idxmax(axis=0,
skipna=True)
Parameters
axis |
It is an integer or string type parameter. It specifies the axis to use. 0 or index for rows, 1 or columns for columns. |
skipna |
It is a Boolean parameter. This parameter specifies excluding null values. If an entire row or column is null, the result will be NA. |
Return
It returns a Series that tells about the indexes of maximum values along the specified axis.
Example Codes: DataFrame.idxmax()
Method to Find Indexes of Maximum Values Row-Wise
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 has returned the indexes of maximum Attendance
and Obtained Marks
Example Codes: DataFrame.idxmax()
Method to Find Indexes of Maximum Values Column-Wise
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
The function has returned the indexes column-wise.
Contribute
DelftStack is a collective effort contributed by software geeks like you. If you like the article and would like to contribute to DelftStack by writing paid articles, you can check the write for us page.