02-05-2021



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

Max Pandas
We 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.

level option

For MultiIndex (hierarchical) axis we can specify the level. Output Pandas

Handling NA data using skipna option

Pandas Min Of Two Series

We will use skipna=True to ignore the null or NA data. Let us check what happens if it is set to True ( skipna=True ) Output

numeric_only

Default value is None, we can set it to True ( Minnumeric_only=True

Pandas Min Of Two Columns

) to include only float, int, boolean columns. We can included all by setting it to False ( numeric_only=False ) . Let us see the outputs . Output is here

Groupby Pandas Min

Pandas min index

Pandas Min Index

Pandas Miniconda

PandasPlotting graphsmeansummaxlenstd