ComenzarEmpieza gratis

Reading CSV files

You've joined DataCorp as a junior data analyst. Your first project involves consolidating the employee database, but the data comes from multiple systems using different CSV formats - some comma-separated, others tab-delimited. Being able to handle varying file formats is essential since real-world data rarely comes in a single standardized format.

The Table, CsvReadOptions, and related Tablesaw classes have been imported for you.

Este ejercicio forma parte del curso

Importing Data in Java

Ver curso

Instrucciones del ejercicio

  • Read in "employees.csv" using default options.
  • Read "employees_tab.csv" using a tab delimiter.
  • Print the structure of both tables.

Ejercicio interactivo práctico

Prueba este ejercicio y completa el código de muestra.

public class ReadCSVFiles {
    public static void main(String[] args) {
        try {
            // Read file using default options
            Table standardCsv = Table.____().____("employees.csv");
            
            // Read file using a tab delimiter
            Table tabDelimited = Table.read().csv(CsvReadOptions
                .____("employees_tab.csv")
                .____('\t')
                .build());
            
            // Print the structure of both tables
            System.out.println(____.____());
            System.out.println(____.____());
            
        } catch (Exception e) {
            System.err.println("Error reading CSV files: " + e.getMessage());
        }
    }
}
Editar y ejecutar código