Xử lý và phân tích dữ liệu

Nhập dữ liệu trong Java

Anthony Markham

VP Quant Developer

Chọn cột

  • .selectColumns() tạo một Table mới
// Chọn các cột theo tên
Table nameAndSalary = employees.selectColumns("Name", "Salary");
// Chọn theo kiểu cột
Table numericColumns = employees.selectColumns(
    column -> column.type().equals(ColumnType.DOUBLE) ||
    column.type().equals(ColumnType.INTEGER));
Nhập dữ liệu trong Java

Lọc dữ liệu

  • Lọc hàng với .where()
  • Trả về một Table mới
// Lọc với một điều kiện
Table seniors = employees.where(
    employees.intColumn("Age").isGreaterThanOrEqualTo(65));
// Lọc với nhiều điều kiện
Table targetGroup = employees.where(
    employees.intColumn("Age").isBetweenInclusive(30, 50)
        .and(employees.doubleColumn("Salary")
            .isGreaterThan(75000)));
Nhập dữ liệu trong Java

Sắp xếp dữ liệu

  • Sắp xếp dữ liệu với .sortOn()
    • Sắp xếp tăng dần
  • Trả về một bảng đã sắp xếp mới
  • Dùng .sortDescendingOn() để sắp xếp giảm dần
// Sắp xếp theo một cột (tăng dần)
Table sortedBySalary = employees.sortOn("Salary");
// Sắp xếp theo nhiều cột (hướng tùy chọn)
Table complexSort = employees
    .sortOn("Department") 
    .sortDescendingOn("Salary");
Nhập dữ liệu trong Java

Gộp dữ liệu với summarize

  • Tính thống kê tóm tắt với .summarize()
  • Trả về một bảng mới
import tech.tablesaw.aggregate.AggregateFunctions.*;
// Tóm tắt lương
Table deptSummary = employees.summarize("Salary", mean, count, max).apply();
Mean [Salary] Count [Salary] Max [Salary]
113606.20299999935 1000 199793
  • Mặc định áp dụng cho mọi cột số
Nhập dữ liệu trong Java

Gộp dữ liệu với summarize

  • Có thể gộp dữ liệu phức tạp hơn
// Nhiều phép tổng hợp
Table complexSummary = employees.summarize(
    "Salary", "Age", 
    mean, median, min, max).apply();
Mean [Salary] Median [Salary] Min [Salary] Max [Salary] Mean [Age] Median [Age] Min [Age] Max [Age]
113606.2029 112667 30301 199793 45.6699 46 22 70
Nhập dữ liệu trong Java

Các phương thức xử lý cốt lõi

  • .select() - Chọn các cột cụ thể
    Table selected = employees.select("Name", "Salary");
    
  • .where() - Lọc hàng theo điều kiện
    Table filtered = employees.where(condition);
    
  • .sortOn() - Sắp xếp theo cột
    Table sorted = employees.sortOn("Department", "Salary");
    
  • .summarize() - Tính thống kê
    Table summary = employees.summarize("Salary", mean, max).apply();
    
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...