An analysis of employee attrition patterns, flight-risk drivers, and cost of turnover using Python (Pandas, Matplotlib, Seaborn) and SQL (MySQL & SQLite).
Created by Chetan Rupchandani
Employee turnover is one of the most significant hidden costs for any business. Industry research shows that replacing an employee costs roughly 50% of their annual salary due to recruitment, onboarding, training, and lost productivity.
Using a dataset of 1,470 employees (IBM HR Analytics dataset schema), this project answers four core questions:
- Which departments and job roles lose the most people?
- What are the key drivers of attrition? (e.g., overtime, pay variance)
- What is the total financial cost of turnover to the company?
- Where should HR focus first to get the highest ROI on retention?
- Overall Attrition Rate: 16.1% (237 out of 1,470 employees left).
- Overtime is the #1 Driver: Employees working overtime leave at 30.5%, compared to 10.4% for those who don't — nearly 3x higher flight risk.
- Riskiest Department: Sales has the highest department attrition rate at 20.6%.
- Riskiest Role: Sales Representative at 39.8% attrition.
- Pay Gap: Employees who left earned 29.9% less on average ($4,787/month vs. $6,833/month for stayers).
- Estimated Annual Turnover Cost: ~$6.81 Million, split mainly between Research & Development (
$3.28M) and Sales ($3.26M).
The analysis generates a 4-panel executive dashboard saved in outputs_charts/attrition_dashboard.png:
data/employee_attrition.csv ──> SQLite / MySQL Database ──> SQL Queries (sql/queries.sql)
└──> Pandas Analysis (src/analysis.py) ──> Cost Calculation + Dashboard
- Target Sales First: Sales loses the highest percentage of staff (20.6%), costing $3.26M annually.
- Address Overtime Burnout: Since overtime triples turnover risk, rebalancing workload or adjusting shift caps will significantly improve retention.
- Financial ROI: Reducing Sales attrition by just 10% would save the company approximately $326,147 per year.
attrition_project/
├── data/
│ ├── employee_attrition.csv # Primary dataset (1,470 records)
│ └── make_sample_data.py # Synthetic data generator script
├── sql/
│ └── queries.sql # Business questions answered in SQL
├── src/
│ ├── analysis.py # Main Pandas analysis & chart generator
│ ├── load_to_mysql.py # MySQL data loader script
│ └── run_sql_demo.py # SQLite query runner (no MySQL required)
├── outputs_charts/
│ ├── attrition_dashboard.png # 4-panel executive chart
│ └── attrition_by_department.png # Standalone department plot
├── .gitignore
├── LICENSE # MIT License
├── README.md # Project documentation
├── requirements.txt # Python dependencies
└── RESUME_BULLETS.md # Resume bullet points & interview highlights
python3 -m pip install -r requirements.txtpython3 src/run_sql_demo.pypython3 src/analysis.pyexport MYSQL_PASSWORD="your_password"
python3 src/load_to_mysql.pyDistributed under the MIT License. See LICENSE for details.
