Java 中的数据导入
Anthony Markham
VP Quant Developer
.selectColumns() 会创建一个新的 Table 对象// Select specific columns by name
Table nameAndSalary = employees.selectColumns("Name", "Salary");
// Select by column type
Table numericColumns = employees.selectColumns(
column -> column.type().equals(ColumnType.DOUBLE) ||
column.type().equals(ColumnType.INTEGER));
.where() 筛选行Table 对象// Filter with a single condition
Table seniors = employees.where(
employees.intColumn("Age").isGreaterThanOrEqualTo(65));
// Filtering using multiple conditions
Table targetGroup = employees.where(
employees.intColumn("Age").isBetweenInclusive(30, 50)
.and(employees.doubleColumn("Salary")
.isGreaterThan(75000)));
.sortOn() 排序.sortDescendingOn()// Sort by a single column (ascending)
Table sortedBySalary = employees.sortOn("Salary");
// Sort by multiple columns (custom direction)
Table complexSort = employees
.sortOn("Department")
.sortDescendingOn("Salary");
.summarize() 计算汇总统计import tech.tablesaw.aggregate.AggregateFunctions.*;
// Summarize salary
Table deptSummary = employees.summarize("Salary", mean, count, max).apply();
| 平均值 [Salary] | 计数 [Salary] | 最大值 [Salary] |
|---|---|---|
| 113606.20299999935 | 1000 | 199793 |
// Multiple aggregations
Table complexSummary = employees.summarize(
"Salary", "Age",
mean, median, min, max).apply();
| 平均值 [Salary] | 中位数 [Salary] | 最小值 [Salary] | 最大值 [Salary] | 平均值 [Age] | 中位数 [Age] | 最小值 [Age] | 最大值 [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 中的数据导入