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.
Cet exercice fait partie du cours
Importing Data in Java
Instructions
- Print the structure of
defaultParsing. - Load the file as
customParsingwith"N/A"handled as missing. - Print the structure of
customParsing.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de 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());
}
}
}