Pandas SQL Query: Calculate minimum, maximum and mean salary from employees file
Pandas HR database Queries: Exercise-22 with Solution
Write a Pandas program to calculate minimum, maximum and mean salary from employees file.
EMPLOYEES.csv
Sample Solution :
Python Code :
import pandas as pd
employees = pd.read_csv(r"EMPLOYEES.csv")
departments = pd.read_csv(r"DEPARTMENTS.csv")
job_history = pd.read_csv(r"JOB_HISTORY.csv")
jobs = pd.read_csv(r"JOBS.csv")
countries = pd.read_csv(r"COUNTRIES.csv")
regions = pd.read_csv(r"REGIONS.csv")
locations = pd.read_csv(r"LOCATIONS.csv")
result = job_history.groupby(['employee_id'])
print(employees.agg({'salary': ['min', 'max', 'mean', 'median']}))
Sample Output:
salary min 2100.000000 max 24000.000000 mean 6461.682243 median 6200.000000
Equivalent SQL Syntax:
SELECT * FROM jobs ORDER BY job_title;
Click to view the table contain:
Python Code Editor:
Structure of HR database :
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Pandas program to display the ID for those employees who did two or more jobs in the past.
Next: Write a Pandas program to display the details of jobs in descending sequence on job title.
What is the difficulty level of this exercise?
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/python-exercises/pandas/sql/python-pandas-hr-database-queries-exercise-22.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics