Bắt đầu ngayBắt đầu miễn phí

Làm sạch và tăng cường dữ liệu

TechCorp đang chuyển sang hệ thống HR mới. Bộ dữ liệu cần được làm sạch: loại bỏ các ngoại lệ lương thấp cho thấy lỗi nhập liệu, bỏ các cột hệ thống mới không dùng, và thêm một trường tiền thưởng được tính. Việc làm sạch dữ liệu thường chiếm 80% thời gian phân tích — đây là các kỹ năng thiết yếu.

Các lớp Table, Selection, và DoubleColumn đã được nhập sẵn cho bạn.

Bài tập này là một phần của khóa học

Nhập dữ liệu trong Java

Xem khóa học

Hướng dẫn bài tập

  • Loại bỏ nhân viên có lương dưới $40,000.
  • Xóa cột "JobTitle".
  • Thêm cột PerformanceBonus (5% của lương).

Bài tập tương tác thực hành trực tiếp

Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.

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));
	}
}
Chỉnh sửa và Chạy Mã