A data analysis project that connects Python to a MySQL database using
mysql-connector-python, pulls employee data into a Pandas DataFrame,
and performs HR analytics with Matplotlib visualizations.
- Python
- MySQL + mysql-connector-python
- Pandas
- Matplotlib
- python-dotenv (secure credentials)
Table: employees
| Column | Type | Description |
|---|---|---|
| emp_id | INT | Primary key, auto increment |
| name | VARCHAR(100) | Employee name |
| department | VARCHAR(50) | Department name |
| salary | INT | Monthly salary |
| joining_date | DATE | Date of joining |
| is_active | BOOLEAN | Employment status |
- Average salary by department
- Department-wise employee headcount
- Salary range (max - min) per department
- Active vs inactive employees
- Employees who joined after 2021
- Top 3 highest paid employees
- MySQL connection via
mysql-connector-python - Secure credentials using
.env+python-dotenv - SQL query execution from Python
- Converting query results to Pandas DataFrame
.dt.yearfor datetime filtering.agg()for multiple aggregations- Groupby, sort, filter operations
- Clone the repo
- Install dependencies — run in terminal: pip install mysql-connector-python pandas matplotlib python-dotenv
- Create .env file in project root and add: DB_PASSWORD=yourpassword
- Run company_hr.sql in MySQL Workbench to set up the database
- Open and run analysis.ipynb top to bottom
Never commit your .env file. It is listed in .gitignore.