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
- Saved in
office_addresses.csv. - If the value for office is
NaN, then the employee is remote.
- Saved in
- Employee addresses
- Saved on the first tab of
employee_information.xlsx.
- Saved on the first tab of
- Employee emergency contacts
- 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.
- Saved on the second tab of
- Employee roles, teams, and salaries
- This information has 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:
- This information has been exported from the company's human resources management system into a JSON file titled
{"A2R5H9": { "title": "CEO", "monthly_salary": "$4500", "team": "Leadership" }, ... }
import pandas as pd
# Start coding here... employee_info = pd.read_excel("datasets/employee_information.xlsx")
employee_roles = pd.read_json("datasets/employee_roles.json")
office_addresses = pd.read_csv("datasets/office_addresses.csv")
employee_emergency = pd.read_excel("datasets/employee_information.xlsx", sheet_name = 1, names=["employee_id", "last_name", "first_name", "emergency_contact", "emergency_contact_number", "relationship"], header = None)employee_emergency.head()employee_roles.head()employee_info.head()office_addresses.head()# transpose employee_roles
employee_roles = employee_roles.transpose()
# reset index, and then make a column of employee_id
col = ["employee_id"] + list(employee_roles.columns)
employee_roles.reset_index(inplace = True)
employee_roles.columns = col
employee_roles#join the dataframes
merged_employee = pd.merge(employee_roles, employee_info, on = "employee_id", how = "right")
merged_employeemerged_employee = pd.merge(merged_employee, employee_emergency, on = "employee_id", how = "left")
employees_final = pd.merge(merged_employee, office_addresses, left_on = "employee_country", right_on="office_country", how = "left")
employees_finalemployees_final.set_index("employee_id", inplace = True)columns = [
"employee_first_name", "employee_last_name", "employee_country", "employee_city",
"employee_street", "employee_street_number", "emergency_contact",
"emergency_contact_number", "relationship", "monthly_salary", "team", "title",
"office", "office_country", "office_city", "office_street", "office_street_number"
]
employees_final = employees_final[columns]
employees_finalemployees_final.isnull().sum()for col in [col for col in columns if col.startswith("office")]:
employees_final[col] = employees_final[col].fillna("Remote")
employees_final