# Write a program in Python to find the minimum rank of a particular column in a dataframe

PythonPandasServer Side ProgrammingProgramming

#### Beyond Basic Programming - Intermediate Python

Most Popular

36 Lectures 3 hours

#### Practical Machine Learning using Python

Best Seller

91 Lectures 23.5 hours

#### Practical Data Science using Python

22 Lectures 6 hours

## Solution

Assume, you have a dataframe and minimum rank of a particular column,

 Id Name    Age    Rank
0 1 Adam    12    1.0
1 2 David   13    3.0
2 3 Michael 14    5.0
3 4 Peter   12    1.0
4 5 William 13    3.0

To solve this, we will follow the steps given below −

• Define a dataframe.

• Assign df[‘Age’] column inside rank function to calculate the minimum rank for axis 0 is,

df["Age"].rank(axis=0,method ='min',ascending=True)

### Example

Let’s see the following code to get a better understanding −

import pandas as pd
data = {'Id': [1,2,3,4,5],
'Age': [12,13,14,12,13]}
df = pd.DataFrame(data)
df["Rank"] = df["Age"].rank(axis=0,method ='min',ascending=True)
print(df)

### Output

 Id Name    Age    Rank
0 1 Adam    12    1.0
1 2 David   13    3.0
2 3 Michael 14    5.0
3 4 Peter   12    1.0
4 5 William 13    3.0