
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Write a program in Python to find the minimum age of an employee id and salary in a given DataFrame
Input −
Assume, you have a DataFrame
DataFrame is Id Age Salary 0 1 27 40000 1 2 22 25000 2 3 25 40000 3 4 23 35000 4 5 24 30000 5 6 32 30000 6 7 30 50000 7 8 28 20000 8 9 29 32000 9 10 27 23000
Output −
And, the result for a minimum age of an employee id and salary,
Id Salary 1 2 25000
Solution
To solve this, we will follow the below approaches.
Define a DataFrame
Set the condition to check the DataFrame Age column which is equal to minimum age. Store it in result DataFrame.
result = df[df['Age']==df['Age'].min()]
Filter Id and Salary from result DataFrame. It is defined below,
result[['Id','Salary']]
Example
Let us see the following implementation to get a better understanding.
import pandas as pd data = [[1,27,40000],[2,22,25000],[3,25,40000],[4,23,35000],[5,24,30000], [6,32,30000],[7,30,50000],[8,28,20000],[9,29,32000],[10,27,23000]] df = pd.DataFrame(data,columns=('Id','Age','Salary')) print("DataFrame is\n",df) print("find the minimum age of an employee id and salary\n") result = df[df['Age']==df['Age'].min()] print(result[['Id','Salary']])
Output
DataFrame is Id Age Salary0 1 27 40000 1 2 22 25000 2 3 25 40000 3 4 23 35000 4 5 24 30000 5 6 32 30000 6 7 30 50000 7 8 28 20000 8 9 29 32000 9 10 27 23000 find the minimum age of an employee id and salary Id Salary 1 2 25000
- Related Articles
- Write a program in Python to find which column has the minimum number of missing values in a given dataframe
- Write a program in Python to find the minimum rank of a particular column in a dataframe
- Program to find average salary excluding the minimum and maximum salary in Python
- Write a Python program to trim the minimum and maximum threshold value in a dataframe
- Write a program in Python to transpose the index and columns in a given DataFrame
- Write a Python function which accepts DataFrame Age, Salary columns second, third and fourth rows as input and find the mean, product of values
- Write a Python program to reshape a given dataframe in different ways
- Write a program in Python to modify the diagonal of a given DataFrame by 1
- Write a program in Python to convert a given dataframe to a LaTex document
- Write a program in Python to caluculate the adjusted and non-adjusted EWM in a given dataframe
- Write a program in Python to localize Asian timezone for a given dataframe
- Write a program in Python to remove first duplicate rows in a given dataframe
- Write a program in Python to count the total number of leap years in a given DataFrame
- Write a Python program to find the mean absolute deviation of rows and columns in a dataframe
- Write a program in Python to find the lowest value in a given DataFrame and store the lowest value in a new row and column

Advertisements