ComeçarComece de graça

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.

Este exercício faz parte do curso

Importing Data in Java

Ver curso

Instruções do exercício

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

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

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());
        }
    }
}
Editar e executar o código