Categories
Python Answers

How to find row where values for column is maximal in a Python Pandas DataFrame?

Spread the love

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'])
index_max = df['A'].idxmax()

to create a data frame with some random numbers in columns A, B and C with

df = pandas.DataFrame(np.random.randn(5,3),columns=['A','B','C'])

Then we get the index with the max value of column A with

index_max = df['A'].idxmax()

Conclusion

To find row where values for column is maximal in a Python Pandas DataFrame, we can use the idxmax method.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *