w3resource

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:

Employees Table

Departments Table

Countries Table

Job_History Table

Jobs Table

Locations Table

Regions Table

Python Code Editor:

Structure of HR database :

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?



Become a Patron!

Follow us on Facebook and Twitter for latest update.

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