การจัดการค่าที่หายไปใน JSON
ขณะรวมข้อมูลพนักงาน คุณพบว่าบางรายการมีข้อมูลไม่ครบ โดยระบุว่า "N/A" ก่อนวิเคราะห์ข้อมูล จำเป็นต้องระบุช่องว่างเหล่านี้และจัดการให้เรียบร้อยเสียก่อน
Tablesaw สามารถกำหนดค่าให้รู้จัก placeholder แบบกำหนดเองเป็นค่าที่หายไปได้ ช่วยให้ตรวจจับและกรองรายการที่ไม่ครบถ้วนได้อย่างสะดวก
คลาส JsonReader, JsonReadOptions และ Table ถูก import ไว้ให้แล้ว
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การนำเข้าข้อมูลใน Java
คำแนะนำการฝึกหัด
- กำหนดค่า JSON options ให้ถือว่า "N/A" เป็นค่าที่หายไป
- โหลดข้อมูลพนักงานลงในตาราง
- กรองแถวที่ไม่มีค่าในคอลัมน์แผนก
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
public class MissingValues {
public static void main(String[] args) {
// Configure "N/A" as missing
JsonReadOptions options = JsonReadOptions
.builder("employees_missing.json")
.____("N/A")
.build();
// Load employee data
Table employees = new ____().read(options);
System.out.println("All employees:");
System.out.println(employees);
// Filter for missing department
Table missingDept = employees.where(
employees.stringColumn("department").____()
);
System.out.println("\nEmployees with missing department:");
System.out.println(missingDept);
}
}