HR Analytics:用 Python 预测员工流失
Hrant Davtyan
Assistant Professor of Data Science American University of Armenia
# 将 "salary" 列转换为分类类型
data.salary = data.salary.astype('category')
# 指定类别顺序
data.salary = data.salary.cat.reorder_categories(['low',
'medium',
'high'])
# 用整数编码类别
data.salary = data.salary.cat.codes
| 旧值 | 新值 |
|---|---|
| low | 0 |
| medium | 1 |
| high | 2 |
# 生成哑变量并保存到新 DataFrame
departments = pd.get_dummies(data.department)
示例输出:
IT RandD accounting hr management marketing product_mng sales support technical
0 0 0 0 0 0 0 0 0 0 1
departments.head()
IT RandD accounting hr management marketing product_mng sales support technical
0 0 0 0 0 0 0 0 0 0 1
departments = departments.drop("technical", axis = 1)
departments.head()
IT RandD accounting hr management marketing product_mng sales support
0 0 0 0 0 0 0 0 0 0
HR Analytics:用 Python 预测员工流失