Understand the idea
idxmax() returns the largest known value’s row label, rather than its value or numbered position.
Illustrative data
Click the highlighted code to change the result.
df[].idxmax()| row | reading | temperature |
|---|---|---|
| 101 | 12 | 22 |
| 106 | 15 | 25 |
| 103 | 19 | 24 |
| 109 | 13 | 20 |
Result
Largest reading: 19. Its row label is 103; its position is 2.
Follow the code
label = df["reading"].idxmax()
row = df.loc[label]
row[["hours", "reading"]]What the syntax does
label = df["reading"].idxmax()- Find the label of the largest reading, not its value or position.
| row | sample | hours | reading |
|---|---|---|---|
| 101 | R1 | 1 | 12 |
| 109 | R2 | 4 | 4 |
| 103 | R3 | 6 | 19 |
| 150 | R4 | 3 | 8 |
| 106 | R5 | 2 | 7 |
| 118 | R6 | 5 | 15 |
Your task · FollowWhich label identifies the largest
Which label identifies the largest reading?
- Use all rows of
df. - Display the index label of the largest
reading. - Use
idxmax() - Return the label rather than its
readingor position.
Setup is included in the editor.
Hint
The result is a label suitable for loc, not the largest measurement.
Reveal solution
Keep the supplied setup and replace the Your work section with this example.
df["reading"].idxmax()