Skip to content

Informatics Practices · Ch 3 — Data Handling using Pandas – II

Calculating Minimum Values

3.2.2

Calculating Minimum Values

The min() method on a DataFrame returns the smallest value from each column (or each row, if you specify the axis). It works across all data types — for numbers it gives the numerical minimum, and for strings it gives the alphabetically smallest value.

When you call df.min() without any arguments, it computes the minimum of every column in the DataFrame. For example, if you have a DataFrame df containing student marks, print(df.min()) will show the lowest mark in each subject column, and also the alphabetically first name in the Name column.

Note

The output of df.min() is a Series, with the column names as the index and the minimum values as the data. The dtype of the result will be object if any column contains strings, because Pandas treats the entire Series as having a mixed type.

Finding Minimum Marks for a Specific Student

The textbook demonstrates this with a practical example: finding the minimum marks obtained by the student 'Mishti' across all unit tests for each subject.

First, you filter the DataFrame to get only the rows where the Name column equals 'Mishti':

dfMishti = df.loc[df.Name == 'Mishti']

This creates a new DataFrame dfMishti containing only Mishti's records. Printing it shows all her unit test scores:

NameUTMathsScienceS.StHindiEng
Mishti11522252222
Mishti21821252423
Mishti31718202520
Now, to get the minimum marks in each subject (ignoring the UT column), you select only the subject columns and apply min():
dfMishti[['Maths','Science','S.St','Hindi','Eng']].min()

The output is:

Maths      15
Science    18
S.St       20
Hindi      22
Eng        20
dtype: int64
``` …
Table 3.8Output of df.min() -- minimum value per column
ColumnMin Value
NameAshravy
UT1
Maths12
Science15
S.St15
Hindi15
DefinitionProgram 3-3

Write the statements to display the minimum marks obtained by a particular student 'Mishti' in all the unit tests for each subject. This shows min() applied to a student-filtered slice of the DataFrame, selecting only the subject …