開始使用免費開始

資料清理與強化

TechCorp 正在移轉到新的 HR 系統。資料集需要清理:移除因輸入錯誤而出現的低薪離群值、刪除新系統不會使用的欄位,並加入計算出的獎金欄位。資料清理通常占分析時間的 80%,這些技能相當重要。

TableSelectionDoubleColumn 類別已為你匯入。

本練習屬於課程

Java 中的資料匯入

檢視課程

練習說明

  • 移除薪資低於 $40,000 的員工。
  • 移除 "JobTitle" 欄位。
  • 新增 PerformanceBonus 欄位(薪資的 5%)。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

public class DataExploration {
	public static void main(String[] args) {

        Table employees = Table.read().csv("employees.csv");

        // Remove employees with salaries below $40,000
        Selection lowSalaries = employees.intColumn("Salary").isLessThan(____);
        Table cleanedEmployees = employees.____(lowSalaries);

        // Remove the JobTitle column
        Table streamlined = cleanedEmployees.____("JobTitle");

        DoubleColumn performanceBonus = streamlined.intColumn("Salary").asDoubleColumn()
            .map(salary -> salary * 0.05);
        performanceBonus.setName("PerformanceBonus");

        // Add the PerformanceBonus column
        Table enhancedEmployees = streamlined.____(performanceBonus);

        System.out.println("Total employees after cleaning: " + enhancedEmployees.rowCount());
        System.out.println("\nFirst 5 rows of enhanced dataset:");
        System.out.println(enhancedEmployees.first(5));
	}
}
編輯並執行程式碼