Procesarea CSV cu Tablesaw

Importul datelor în Java

Anthony Markham

VP Quant Developer

Citirea fișierelor CSV

  • Citiți fișiere CSV folosind read().csv()
import tech.tablesaw.api.Table;
// Read in data
Table dataTable = Table.read().csv("data.csv");
  • Detectează automat tipurile de coloane, creând un obiect Table structurat 💡
Importul datelor în Java

Opțiuni de citire CSV

  • Utilizați CsvReadOptions pentru mai mult control
import tech.tablesaw.io.csv.CsvReadOptions;
CsvReadOptions options = CsvReadOptions.builder("data.csv")

.separator(';') // Use semicolon as delimiter
.header(true) // First row contains headers
.missingValueIndicator("N/A") // Treat "N/A" as missing data
.build();
// Load the table using the custom options Table table = Table.read().csv(options);
Importul datelor în Java

Scrierea fișierelor CSV

  • Utilizați write().csv() pentru export CSV de bază
  • Importat prin clasa Table
  • Păstrează tipurile de coloane și structura
  • Gestionează automat caracterele speciale
// Write dataTable to output.csv
dataTable.write().csv("output.csv");
Importul datelor în Java

Opțiuni de scriere CSV

  • Utilizați CsvWriteOptions pentru a specifica opțiunile de scriere
CsvWriteOptions writeOptions = CsvWriteOptions
    .builder("output.csv")

.header(true) // Include column headers
.separator(';') // Use semicolon delimiter
.quoteAlways(true) // Quote all fields
.lineEnd("\r\n") // Windows-style line endings
.build();
// Write the CSV using the custom options
Table.write().csv(writeOptions);
Importul datelor în Java

Flux de lucru CSV

  • Flux complet: citire -> inspecție -> procesare -> scriere
  • Operații nedistructive (creează fișiere noi) 📁
// Read CSV, modify, and write back
Table students = Table.read().csv("students.csv");

// View structure
System.out.println(students.structure());

// Save as new file
students.write().csv("students_processed.csv");
Importul datelor în Java

Să exersăm!

Importul datelor în Java

Preparing Video For Download...