處理 JSON 中的遺漏值
在合併員工資料時,你發現有些紀錄的資訊不完整,並以「N/A」標示。在分析之前,你需要先找出這些缺口並妥善處理。
你可以設定 Tablesaw 將自訂的占位符視為遺漏值,這樣就能偵測並篩出不完整的紀錄。
JsonReader、JsonReadOptions 和 Table 類別都已為你匯入。
本練習屬於課程
Java 中的資料匯入
練習說明
- 設定 JSON 選項,將「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);
}
}