Pandas is one of those packages and makes importing and analyzing data much easier. Pandas dataframe.min function returns the minimum of the values in the given object. If the input is a series, the method will return a scalar which will be the minimum of the values in the series. Brand: Price: Year: Honda Civic: 22000: 2014: Ford Focus: 27000: 2015: Toyota Corolla: 25000: 2016: Toyota Corolla: 29000: 2017: Audi A4: 35000: 2018.
In this tutorial we will learn how to select row with maximum and minimum value in python pandas
- Get the entire row which has the maximum value of a column in python pandas
- Get the entire row which has the minimum value of a column in python pandas.
Let’s see example of both
Create dataframe:
So the resultant dataframe will be
Get the entire row which has the maximum value in python pandas:
So let’s extract the entire row where score is maximum i.e. get all the details of student with maximum score as shown below
Explanation:
df[‘Score’].idxmax()– > returns the index of the row where column name “Score” has maximum value.
df.loc[]-> returns the row of that index
so the output will be
Get the entire row which has the minimum value in python pandas:
So let’s extract the entire row where score is minimum i.e. get all the details of student with minimum score as shown below
so the output will be
PandasWe can minimum number in rows or columns by using min().
Output What is the minimum mark in MATH ? We can get the row or details of the record who got minimum mark in MATH Output is here
Using axis
We will use option axis=0 ( default ) by adding to above code.( The last line is only changed ) Output is here We are getting all the minimum values from the ID column. You can change the DataFrame and then check the minimum value.