Java 中的資料匯入
Anthony Markham
VP Quant Developer
.selectColumns() 會建立一個「新的」Table 物件// 依欄位名稱選取特定欄位
Table nameAndSalary = employees.selectColumns("Name", "Salary");
// 依欄位型別選取
Table numericColumns = employees.selectColumns(
column -> column.type().equals(ColumnType.DOUBLE) ||
column.type().equals(ColumnType.INTEGER));
.where() 篩選列Table 物件// 使用單一條件篩選
Table seniors = employees.where(
employees.intColumn("Age").isGreaterThanOrEqualTo(65));
// 使用多個條件篩選
Table targetGroup = employees.where(
employees.intColumn("Age").isBetweenInclusive(30, 50)
.and(employees.doubleColumn("Salary")
.isGreaterThan(75000)));
.sortOn() 整理資料.sortDescendingOn()// 以單一欄位排序(遞增)
Table sortedBySalary = employees.sortOn("Salary");
// 以多欄位排序(自訂方向)
Table complexSort = employees
.sortOn("Department")
.sortDescendingOn("Salary");
.summarize() 計算摘要統計import tech.tablesaw.aggregate.AggregateFunctions.*;
// 彙總薪資
Table deptSummary = employees.summarize("Salary", mean, count, max).apply();
| Mean [Salary] | Count [Salary] | Max [Salary] |
|---|---|---|
| 113606.20299999935 | 1000 | 199793 |
// 多種聚合
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 |
.select():選取特定欄位Table selected = employees.select("Name", "Salary");
.where():依條件篩選列Table filtered = employees.where(condition);
.sortOn():依欄位排序Table sorted = employees.sortOn("Department", "Salary");
.summarize():計算統計Table summary = employees.summarize("Salary", mean, max).apply();
Java 中的資料匯入