Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Calculate and Visualize Turnover | Introduction to People Analytics with Python
Python for People Analytics
Sektion 1. Kapitel 5
single

single

bookChallenge: Calculate and Visualize Turnover

Stryg for at vise menuen

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.

Opgave

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.

Løsning

Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 1. Kapitel 5
single

single

Spørg AI

expand

Spørg AI

ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

some-alt