CSV 解析オプションの処理
従業員パフォーマンスファイルには、手動入力のミスによる "N/A" の値が含まれています。インポート時にこれを適切に処理しないと、テキスト文字列として扱われてしまい、列の型が正しく認識されず、計算にも支障が出ます。欠損値のインジケーターをあらかじめ正しく指定しておくことで、後のデバッグに費やす時間を大幅に節約できます。
Table クラスと CsvReadOptions クラスはすでにインポートされています。
この演習はコースの一部です
Java でのデータインポート
演習の手順
defaultParsingの構造を出力しましょう。"N/A"を欠損値として処理するよう設定し、ファイルをcustomParsingとして読み込みましょう。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());
}
}
}