Get startedGet started for free

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.

This exercise is part of the course

Importing Data in Java

View Course

Exercise instructions

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

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

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());
        }
    }
}
Edit and Run Code