Skip to content
Project: Consolidating Employee Data
You just got hired as the first and only data practitioner at a small business experiencing exponential growth. The company needs more structured processes, guidelines, and standards. Your first mission is to structure the human resources data. The data is currently scattered across teams and files and comes in various formats: Excel files, CSVs, JSON files...
You'll work with the following data in the datasets
folder:
- Office addresses are currently saved in
office_addresses.csv
. If the value for office isNaN
, then the employee is remote. - Employee addresses are saved on the first tab of
employee_information.xlsx
. - Employee emergency contacts are saved on the second tab of
employee_information.xlsx
; this tab is calledemergency_contacts
. However, this sheet was edited at some point, and the headers were removed! The HR manager let you know that they should be:employee_id
,last_name
,first_name
,emergency_contact
,emergency_contact_number
, andrelationship
. - Employee roles, teams, and salaries have been exported from the company's human resources management system into a JSON file titled
employee_roles.json
. Here are the first few lines of that file:
{"A2R5H9": { "title": "CEO", "monthly_salary": "$4500", "team": "Leadership" }, ... }
Imports
import pandas as pd
Reading Data
Office Addresses
off_add = pd.read_csv('datasets/office_addresses.csv')
print(off_add.head()) # Cheking data
print(list(off_add.columns))
Employees Information
1: Addresses
addresses_cols = ['employee_id', 'employee_country', 'employee_city',
'employee_street', 'employee_street_number']
emp_inf_add = pd.read_excel('datasets/employee_information.xlsx',
sheet_name = 0,
usecols = addresses_cols)
print(emp_inf_add.head()) # Cheking data
print(list(emp_inf_add.columns))
2: Emergency Contacts
emergency_contacts_header = ['employee_id', 'last_name', 'first_name',
'emergency_contact', 'emergency_contact_number',
'relationship']
emp_inf_eme_con = pd.read_excel('datasets/employee_information.xlsx',
sheet_name = 1,
header = None,
names = emergency_contacts_header)
print(emp_inf_eme_con.head()) # Cheking data
print(list(emp_inf_eme_con.columns))
Employess Roles
emp_rol = pd.read_json('datasets/employee_roles.json',
orient = 'index')
print(emp_rol.head()) # Cheking data
print(list(emp_rol.columns))
Merging Data
Addresses and Office
employees = emp_inf_add.merge(off_add,
how = 'left',
left_on = 'employee_country',
right_on = 'office_country')
print(employees.head())
print(list(employees.columns))
Employees and Roles
employees = employees.merge(emp_rol,
left_on = 'employee_id',
right_index = True)
print(employees.head())
print(list(employees.columns))