開始使用免費開始

離職員工的百分比

欄位 churn 提供員工是否已離職的資訊:

  • 當此欄位的值為 0,代表員工仍在職
  • 當此欄位的值為 1,代表員工已離職

現在來計算離職率:

  • 你會先分別計算變數 churn 取值為 1 與 0 的次數。
  • 然後將這兩個次數各自除以總人數,再乘以 100,得到離職與留任的百分比。

本練習屬於課程

HR 分析:用 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)
編輯並執行程式碼