Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Calculate and Visualize Turnover | Introduction to People Analytics with Python
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Python for People Analytics
Sectionย 1. Chapterย 5
single

single

bookChallenge: Calculate and Visualize Turnover

Swipe to show menu

Understanding employee turnover is vital in people analytics because it provides insight into workforce stability and organizational health. Turnover rate measures the proportion of employees who leave an organization within a specific period, typically a year, relative to the average number of employees. This metric helps HR professionals identify trends, forecast staffing needs, and address potential issues related to retention. Visualizing turnover data makes patterns more accessible and actionable, supporting data-driven decision-making.

123456789101112131415161718
# Lists of employee names current_employees = ["Alice", "Bob", "Charlie", "David", "Eva", "Frank", "Grace"] former_employees = ["Helen", "Ian", "Jack"] # Calculate turnover rate total_employees = len(current_employees) + len(former_employees) turnover_rate = (len(former_employees) / total_employees) * 100 # Basic bar chart setup import matplotlib.pyplot as plt categories = ["Current Employees", "Former Employees"] counts = [len(current_employees), len(former_employees)] plt.bar(categories, counts, color=["skyblue", "salmon"]) plt.ylabel("Number of Employees") plt.title("Employee Status Overview") plt.show()
copy

When creating HR reports, annotating your charts with key metricsโ€”such as the turnover rateโ€”adds valuable context. To annotate a bar chart in matplotlib, you can use the plt.text() function to display the turnover rate directly above the bars or in the title. This helps stakeholders quickly interpret the results and understand the scale of workforce changes. Interpreting turnover data involves considering not just the percentage, but also the underlying causes and potential impact on the organization. High turnover may signal issues with employee satisfaction, culture, or management practices, while low turnover could indicate stability or, in some cases, stagnation.

Task

Swipe to start coding

Implement a Python function that calculates the turnover rate from two lists and visualizes the result.

  • Calculate the total number of employees by summing the lengths of current_employees and former_employees.
  • Compute the turnover rate as the percentage of former_employees out of the total number of employees.
  • Create a bar chart with categories for current and former employees, using the counts from each list.
  • Annotate the bar chart with the calculated turnover rate.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Sectionย 1. Chapterย 5
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

some-alt