离职员工的百分比
列 churn 提供了员工是否已经离开公司的信息:
- 如果该列的值为 0,则该员工仍在公司。
- 如果该列的值为 1,则该员工已离职。
现在来计算离职率:
- 首先分别统计变量
churn取值为 1 和取值为 0 的次数; - 然后将这两个计数各自除以员工总数,并将结果乘以 100,得到离职和在职员工所占的百分比。
本练习是课程的一部分
HR Analytics:用 Python 预测员工流失
练习说明
- 使用
len()函数获取观测总数,并将其保存为员工总数。 - 打印已离职和仍在职的员工人数。
- 打印已离职和仍在职的员工百分比。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# 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)