Tablesawの概要

Java でのデータインポート

Anthony Markham

VP Quant Developer

Tablesawのインポート

  • データ操作用ライブラリ
  • 主なインポート: import tech.tablesaw.api.*
  • 特定機能向けの追加インポート(例):
    • import tech.tablesaw.api.DoubleColumn
    • import tech.tablesaw.api.StringColumn
  • 統計操作: import tech.tablesaw.aggregate.*
1 https://jtablesaw.github.io/tablesaw/
Java でのデータインポート

表形式

  • 行と列でデータを整理
  • 列 = 変数/特徴量
  • 行 = 観測値/インスタンス

列と行にラベルが付いたサンプルテーブルの画像。

Java でのデータインポート

表形式

  • 配列やコレクションでデータを格納可能
// Traditional Java approach (cumbersome)
import java.util.Arrays;
import java.util.List;
List<String> names = Arrays.asList("Anna", "Bob", "Carlos");
List<Integer> ages = Arrays.asList(25, 34, 42);
Java でのデータインポート

テーブルの作成

  • 作成方法: ゼロから、外部ファイル、または既存の列から
// Creating from scratch
Table employees = Table.create("Employees")
    .addColumns(
        StringColumn.create("Name", "John", "Lisa", "Omar"),
        DoubleColumn.create("Salary", 50000, 60000, 55000)
    );
// From existing columns
StringColumn dept = StringColumn.create("Department", 
    "Sales", "Marketing", "Engineering");
Table departments = Table.create("Departments", dept);
  • addColumns() および create() メソッド
Java でのデータインポート

テーブルのメタデータ

  • 次元数: table.shape()
  • 列名: table.columnNames()
  • テーブル構造: table.structure()
  • データのプレビュー: table.first(n), table.last(n)
// Print dimensions
System.out.println(data.shape());  // [rows, columns]
[10, 4]
Java でのデータインポート

テーブルのメタデータ

// Print column names
System.out.println(table.columnNames());
[Day, Temperature, Precipitation]
// Print detailed structure
System.out.println(table.structure());
         Structure of table          
 Index  |   Column Name   |  Column Type  |
     0  |            Day  |       STRING  |
     1  |    Temperature  |       DOUBLE  |
     2  |  Precipitation  |       DOUBLE  |
Java でのデータインポート

テーブルのメタデータ

// Preview first three rows
System.out.println(table.first(3));
                  table                  
    Day     |  Temperature  |  Precipitation  |
    Monday  |         22.5  |              0  |
   Tuesday  |           24  |            2.5  |
 Wednesday  |         23.2  |            5.2  |
Java でのデータインポート

列の追加

  • 列の追加: table.addColumns(newColumn)
// Add a new column
DoubleColumn bonus = DoubleColumn.create("Bonus", 1000, 1500, 2000);
employees = employees.addColumns(bonus);
Java でのデータインポート

列の削除と名前変更

// Remove a column
employees = employees.removeColumns("StartDate");
// Rename a column
employees.column("Salary").setName("AnnualSalary");
// Get the type of column
employees.column("Salary").type();
ColumnType.INTEGER

$$

  • 変更後のテーブルが返されます 💡
Java でのデータインポート

まとめ

メソッド/構文 説明
Table.create("TableName") 指定した名前のテーブルを作成
StringColumn.create("ColumnName", values) 文字列列を作成
table.shape() 次元数を [行, 列] で返す
table.columnNames() テーブルの列名一覧を返す
table.structure() テーブルの構造情報を表示
table.first(n) 先頭n行を返す
table.last(n) 末尾n行を返す
table.addColumns(newColumn) テーブルに列を追加
1 https://www.javadoc.io/doc/tech.tablesaw/tablesaw-core
Java でのデータインポート

練習しましょう!

Java でのデータインポート

Preparing Video For Download...