Sometimes, we want to find row where values for column is maximal in a Python Pandas DataFrame.
In this article, we’ll look at how to find row where values for column is maximal in a Python Pandas DataFrame.
How to find row where values for column is maximal in a Python Pandas DataFrame
To find row where values for column is maximal in a Python Pandas DataFrame, we can use the idxmax
method.
For instance, we write
import pandas
import numpy as np
df = pandas.DataFrame(np.random.randn(5,3),columns=['A','B','C'])
df['A'].idxmax()
to create the df
data frame.
And then we use
df['A'].idxmax()
to get the index of the highest value in columns A.
Conclusion
To find row where values for column is maximal in a Python Pandas DataFrame, we can use the idxmax
method.