Percentage of employees who churn
The column churn
is providing information about whether an employee has left the company or not is the column churn
:
- if the value of this column is 0, the employee is still with the company
- if the value of this column is 1, then the employee has left the company
Let’s calculate the turnover rate:
- you will first count the number of times the variable
churn
has the value 1 and the value 0, respectively - you will then divide both counts by the total, and multiply the result by 100 to get the percentage of employees who left and stayed
This exercise is part of the course
HR Analytics: Predicting Employee Churn in Python
Exercise instructions
- Use the
len()
function to get the total number of observations and save it as the number of employees. - Print the number of employees who left and stayed.
- Print the percentage of employees who left and stayed.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Use len() function to get the total number of observations and save it as the number of employees
n_employees = ____(data)
# Print the number of employees who left/stayed
print(data.churn.____())
# Print the percentage of employees who left/stayed
print(data.churn.____()/____*100)