開始使用免費開始

設定 CSV 解析選項

員工績效檔案因人工輸入錯誤而含有 "N/A"。若在匯入時未妥善處理,這些值會被當成文字字串,而不是遺漏值,導致欄位型別判定錯誤,計算也會出問題。事先正確標示遺漏值指標,可以省下後續大量除錯時間。

已為你匯入 TableCsvReadOptions 類別。

本練習屬於課程

Java 中的資料匯入

檢視課程

練習說明

  • 印出 defaultParsing 的結構。
  • 讀取檔案為 customParsing,並將 "N/A" 視為遺漏值。
  • 印出 customParsing 的結構。

動手互動練習

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

public class ParseCSVFiles {
    public static void main(String[] args) {
        try {
            Table defaultParsing = Table.read().csv("employee_performance.csv");
            System.out.println("Default parsing structure:");
            // Print the structure of defaultParsing
            System.out.println(defaultParsing.____);
            System.out.println(defaultParsing.first(3).print());

            // Load the file as customParsing with "N/A" handled as missing
            Table customParsing = Table.read().csv(
                ____.builder("employee_performance.csv")
                    .____(____)
                    .build()
            );

            System.out.println("\nCustom missing value parsing structure:");
            // Print the structure of customParsing
            System.out.println(customParsing.____);
            System.out.println(customParsing.first(3).print());

        } catch (Exception e) {
            System.err.println("Error reading CSV files: " + e.getMessage());
        }
    }
}
編輯並執行程式碼