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 ejercicio forma parte del curso
Importing Data in Java
Instrucciones del ejercicio
- Print the structure of
defaultParsing. - Load the file as
customParsingwith"N/A"handled as missing. - Print the structure of
customParsing.
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
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());
}
}
}