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 中的数据导入

表方法

String tableName = employees.name();
employees
// Row and column counts
int rowCount = employees.rowCount();
int columnCount = employees.columnCount();
1000
5
Java 中的数据导入

列类型

  • 强类型:每列有固定数据类型
    • 提升性能,便于调试
  • 示例:
    • StringColumn - 文本数据
    • IntColumnDoubleColumn - 数值
    • 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 中的数据导入

Selections(选择集)

  • 符合条件的行索引集合
  • 例:
    • .isGreaterThan().isLessThan()
    • .isEqualTo()
    • .isAfter()

$$

// Create a selection of rows
Selection highEarners = employees.doubleColumn("Salary")
    .isGreaterThan(70000);
Java 中的数据导入

基于选择集过滤

// 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 recentHires = employees.dateColumn("HireDate")
    .isAfter(LocalDate.of(2020, 1, 1));

Selection highPaidRecent = highEarners.and(recentHires);
Java 中的数据导入

Passons à la pratique !

Java 中的数据导入

Preparing Video For Download...