建立虛擬變數(dummies)
現在你要轉換 department 這個變數。根據先前觀察到的值,你已經知道它是名目尺度。為了進行轉換,將使用所謂的 虛擬變數(dummy variables)。
本練習屬於課程
HR 分析:用 Python 預測員工流失
練習說明
- 針對資料裡的 department 欄位呼叫 get_dummies(),並將結果存成名為
departments的新 DataFrame。 - 快速查看新 DataFrame
departments的前 5 列。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Get dummies and save them inside a new DataFrame
departments = pd.____(____.department)
# Take a quick look to the first 5 rows of the new DataFrame called departments
print(____.____())