This project analyzes company-wide workforce data to understand headcount distribution and the relationship between job satisfaction and attrition risk.
C7.2 Business Problem
The HR leadership team wants a clear picture of where employees are concentrated across departments, and whether job satisfaction meaningfully predicts who is likely to leave.
C7.3 Dataset Description
Column
Description
employee_id
Unique employee identifier
department
Department name
satisfaction_score
Job satisfaction score (1-10)
attrition
Whether the employee left (1) or stayed (0)
salary_band
Salary band (Low, Medium, High)
Sample scope: 200 employees across 5 departments.
C7.4 Objectives
Understand headcount distribution across departments
Analyze the relationship between satisfaction score and attrition
Identify satisfaction score thresholds linked to higher attrition risk
Recommend HR interventions to reduce attrition
C7.5 Step-by-Step Solution
Step 1: Load the HR dataset into Pandas
Step 2: Clean missing values and verify data types
Step 3: Visualize headcount by department using a pie chart
Step 4: Create a scatter plot of satisfaction score vs attrition
Step 5: Calculate average satisfaction for attrited vs retained employees
Step 6: Summarize insights and HR recommendations
C7.6 Complete Python Code
► hr_analytics.py
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv("hr_workforce.csv")
df = df.dropna(subset=['satisfaction_score'])
headcount = df['department'].value_counts()
print("Headcount by Department:\n", headcount)
avg_satisfaction = df.groupby('attrition')['satisfaction_score'].mean()
print("Avg Satisfaction (0=Stayed, 1=Left):\n", avg_satisfaction.round(2))
plt.scatter(df["satisfaction_score"], df["attrition"], alpha=0.5)
plt.title("Satisfaction vs Attrition")
plt.savefig("satisfaction_scatter.png")
C7.7 Expected Output
Output
Avg Satisfaction (0=Stayed, 1=Left): 0 7.4 1 4.8
C7.8 Visualizations
Figure C7.1 — Headcount distribution across departments.Figure C7.2 — Relationship between job satisfaction and attrition.
C7.9 Key Insights
Sales is the largest department (120 employees, ~30% of headcount), making it the highest-leverage area for any company-wide HR initiative.
Employees who left the company had a noticeably lower average satisfaction score (4.8) compared to those who stayed (7.4).
Attrition risk rises sharply below a satisfaction score of ~5.5, suggesting a practical early-warning threshold for HR monitoring.
C7.10 Business Recommendations
Implement a quarterly satisfaction pulse survey, with automatic flags for any employee scoring below 5.5, to enable proactive retention conversations.
Since Sales is the largest department, prioritize manager training and engagement initiatives there first for maximum company-wide impact.
Build a simple satisfaction-monitoring dashboard (reusing this project's code) that HR can re-run monthly on refreshed data.