

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- Program to find average salary excluding the minimum and maximum salary in Python
- Write a program in Python to find the minimum rank of a particular column in a dataframe
- Write a program in Python to find which column has the minimum number of missing values 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 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
- Find max and second max salary for a MySQL Employee table?
- Write a program in Python to modify the diagonal of a given DataFrame by 1
- Write a Python program to reshape a given dataframe in different ways
- Write a Python program to find the mean absolute deviation of rows and columns in a dataframe
- Write a program in Python to caluculate the adjusted and non-adjusted EWM in a given dataframe
- Write a program in Python to convert a given dataframe to a LaTex document
- Write a program in Python to localize Asian timezone for a given dataframe
- Write a program in Python to count the total number of leap years in a given DataFrame
- Write a Python code to rename the given axis in a dataframe
Advertisements