Cấu trúc dữ liệu trong Tablesaw

Nhập dữ liệu trong Java

Anthony Markham

VP Quant Developer

Cấu trúc dữ liệu cốt lõi

  • Table: Vùng chứa chính (giống DataFrame)
Table employees = Table.create("Employees");
  • Column: Chứa các giá trị cùng kiểu
StringColumn nameCol = StringColumn.create("Name");
  • Row: Đại diện một bản ghi
Row firstRow = employees.row(0);
Nhập dữ liệu trong Java

Phương thức của Table

String tableName = employees.name();
employees
// Số hàng và số cột
int rowCount = employees.rowCount();
int columnCount = employees.columnCount();
1000
5
Nhập dữ liệu trong Java

Kiểu cột

  • Kiểu mạnh = mỗi cột có kiểu dữ liệu cố định
    • Tăng hiệu năng và giúp dễ debug hơn
  • Ví dụ:
    • StringColumn - Dữ liệu văn bản
    • IntColumn, DoubleColumn - Giá trị số
    • BooleanColumn - Giá trị Đúng/Sai
    • Dữ liệu chuỗi thời gian:
      • DateColumn - ngày lịch (2024-03-05)
      • DateTimeColumn - ngày giờ (2024-03-05T14:32)
Nhập dữ liệu trong Java

Thao tác theo kiểu cột

  • Mỗi kiểu cung cấp các thao tác chuyên biệt
// Dùng .mean() trên DoubleColumn
DoubleColumn salary = employees.column("Salary");
double averageSalary = salary.mean();
Nhập dữ liệu trong Java

Truy cập dữ liệu

// Lấy một cột cụ thể
StringColumn names = employees.stringColumn("Name");

// Lấy cột kiểu tổng quát names = employees.column("Name");
// Lấy một giá trị từ cột String firstPerson = names.get(0);
// Lấy toàn bộ một hàng Row firstRow = employees.row(0);
// Lấy giá trị từ một hàng double salary = firstRow.getDouble("Salary");
Nhập dữ liệu trong Java

Selections

  • Tập chỉ số hàng thỏa một điều kiện
  • Ví dụ:
    • .isGreaterThan(), .isLessThan()
    • .isEqualTo()
    • .isAfter()

$$

// Tạo Selection các hàng
Selection highEarners = employees.doubleColumn("Salary")
    .isGreaterThan(70000);
Nhập dữ liệu trong Java

Lọc với Selection

// Tạo Selection các hàng
Selection highEarners = employees.doubleColumn("Salary")
    .isGreaterThan(70000);


// Áp dụng Selection để lọc bảng Table highPaidEmployees = employees.where(highEarners);

$$

$$

  • .where() trả về một bảng mới
Nhập dữ liệu trong Java

Toán tử Boolean

  • Kết hợp Selection bằng .and().or()
Selection recentHires = employees.dateColumn("HireDate")
    .isAfter(LocalDate.of(2020, 1, 1));

Selection highPaidRecent = highEarners.and(recentHires);
Nhập dữ liệu trong Java

Cùng luyện tập nào!

Nhập dữ liệu trong Java

Preparing Video For Download...