BaşlayınÜcretsiz başlayın

Handling CSV parsing options

The employee performance file has "N/A" values from manual data entry errors. If not handled during import, these will be treated as text strings instead of missing values, causing incorrect column types and broken calculations. Properly identifying missing value indicators upfront saves hours of debugging later.

The Table and CsvReadOptions classes have been imported for you.

Bu egzersiz, kursun bir parçasıdır

Importing Data in Java

Kursa Göz Atın

Egzersiz talimatları

  • Print the structure of defaultParsing.
  • Load the file as customParsing with "N/A" handled as missing.
  • Print the structure of customParsing.

Uygulamalı etkileşimli egzersiz

Bu egzersizi bu örnek kodu tamamlayarak deneyin.

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());
        }
    }
}
Kodu Düzenle ve Çalıştır