Pandas functions
Pandas Index Max β pd.DataFrame.idxmax()
Pandas idxmax index of maximum value
Pandas idxmax is a very convenient function that will return the index of the maximum value across a specified axis. It is especially useful when trying to figure out the max column values for your rows OR maximum row value for your columns.
Say you have a list of students as your rows, and test scores in your columns. Which test was the highest for each student? .idxmax()
is a one-liner thatβll tell you.
Pseudo code: For a given axis, tell me where the highest value is on the other axis.
Pandas idxmax
Index Max Parameters
Small tip: idxmax works best when your index is consistent. If you start using set_index() or reset_index() then your idxmax might give you back confusing results.
- axis: Which axis would you like to find your highest value intersections for?
Axis=1
means you want to find the highest column for each row.Axis=0
means you want to find the highest row for each column! - skipna (Default=True): Rarely used. By default pandas will skip the NA values. If you donβt want to skip them, set skipna=False.
Letβs look at a fun example of students and test scores