การสร้าง Dummy Variables
ต่อไปจะแปลงตัวแปร department ซึ่งจากค่าที่สังเกตได้ทราบแล้วว่าเป็นข้อมูลแบบ nominal โดยจะใช้สิ่งที่เรียกว่า dummy variables
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
HR Analytics: การพยากรณ์การลาออกของพนักงานด้วย Python
คำแนะนำการฝึกหัด
- ใช้ get_dummies() กับคอลัมน์ department ของชุดข้อมูล แล้วบันทึกผลลัพธ์ไว้ใน DataFrame ใหม่ชื่อ
departments - ดูข้อมูลคร่าว ๆ ของ 5 แถวแรกใน DataFrame ชื่อ
departments
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# 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(____.____())