Santiago Munez
Santiago Munez

Reputation: 2045

Pandas DataFrame Retrieve Value from Column

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!

Upvotes: 4

Views: 4248

Answers (1)

Jeff
Jeff

Reputation: 128948

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

Upvotes: 4

Related Questions