4

Supposely I have dataframe as below:

Idx A B C
0   1 2 3
1   3 4 5
2   2 3 8

The max value of dataframe column B is 4, and I could get the index from df["B"].argmax() which is 1.

The problem is now, how could I get the exact max value of the dataframe column B?

Thanks!

1 Answer 1

4
In [6]: df
Out[6]: 
     A  B  C
Idx         
0    1  2  3
1    3  4  5
2    2  3  8

In [7]: df.max()
Out[7]: 
A    3
B    4
C    8
dtype: int64

In [10]: df['B'].max()
Out[10]: 4

In [8]: df.idxmax()
Out[8]: 
A    1
B    1
C    2
dtype: int64
Sign up to request clarification or add additional context in comments.

2 Comments

Yeap. Now, I have the index from df.idxmax(). How to use this index, to get the value of column A? I have tried something like df["A"](df.idxmax()), but it's not working? Thanks!
df['A'].max() or df['A'](df.idxmax()['A']) is much more verbose

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.