Tablesawのデータ構造

Java でのデータインポート

Anthony Markham

VP Quant Developer

主要なデータ構造

  • Table: 主要なコンテナ(DataFrameに相当)
Table employees = Table.create("Employees");
  • Column: 一定の型の値を保持
StringColumn nameCol = StringColumn.create("Name");
  • Row: 個々のレコードを表す
Row firstRow = employees.row(0);
Java でのデータインポート

Tableのメソッド

String tableName = employees.name();
employees
// Row and column counts
int rowCount = employees.rowCount();
int columnCount = employees.columnCount();
1000
5
Java でのデータインポート

列の型

  • 強い型付け = 各列は固定のデータ型を持つ
    • パフォーマンス向上とデバッグの容易化
  • 例:
    • StringColumn - テキストデータ
    • IntColumn, DoubleColumn - 数値
    • BooleanColumn - 真偽値
    • 時系列データ:
      • DateColumn - 日付 (2024-03-05)
      • DateTimeColumn - 日時 (2024-03-05T14:32)
Java でのデータインポート

列型の操作

  • 各型は専用の操作を提供
// Using .mean() on DoubleColumn
DoubleColumn salary = employees.column("Salary");
double averageSalary = salary.mean();
Java でのデータインポート

データへのアクセス

// Get a specific column
StringColumn names = employees.stringColumn("Name");

// Get a general column names = employees.column("Name");
// Get a value from a column String firstPerson = names.get(0);
// Get an entire row Row firstRow = employees.row(0);
// Get a value from a row double salary = firstRow.getDouble("Salary");
Java でのデータインポート

Selection

  • 条件に一致する行インデックスの集合
  • 例:
    • .isGreaterThan(), .isLessThan()
    • .isEqualTo()
    • .isAfter()

$$

// Create a selection of rows
Selection highEarners = employees.doubleColumn("Salary")
    .isGreaterThan(70000);
Java でのデータインポート

Selectionによるフィルタリング

// Create a selection of rows
Selection highEarners = employees.doubleColumn("Salary")
    .isGreaterThan(70000);


// Apply selection to get a filtered table Table highPaidEmployees = employees.where(highEarners);

$$

$$

  • .where() は新しいテーブルを返す
Java でのデータインポート

ブール演算

  • .and() と .or() でSelectionを組み合わせる
Selection recentHires = employees.dateColumn("HireDate")
    .isAfter(LocalDate.of(2020, 1, 1));

Selection highPaidRecent = highEarners.and(recentHires);
Java でのデータインポート

練習しましょう!

Java でのデータインポート

Preparing Video For Download...