TablesawによるCSV処理

Java でのデータインポート

Anthony Markham

VP Quant Developer

CSVファイルの読み込み

  • read().csv() でCSVファイルを読み込む
import tech.tablesaw.api.Table;
// Read in data
Table dataTable = Table.read().csv("data.csv");
  • 列の型を自動検出し、構造化された Table オブジェクトを生成 💡
Java でのデータインポート

CSV読み込みオプション

  • CsvReadOptions で読み込みを細かく制御
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);
Java でのデータインポート

CSVファイルの書き込み

  • write().csv() で基本的なCSVエクスポート
  • Table クラスと共にインポート
  • 列の型と構造を保持
  • 特殊文字を自動処理
// Write dataTable to output.csv
dataTable.write().csv("output.csv");
Java でのデータインポート

CSV書き込みオプション

  • CsvWriteOptions で書き込みオプションを指定
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);
Java でのデータインポート

CSVワークフロー

  • 完全なワークフロー:読み込み → 検査 → 処理 → 書き込み
  • 非破壊操作(新しいファイルを生成) 📁
// 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");
Java でのデータインポート

練習しましょう!

Java でのデータインポート

Preparing Video For Download...