Importing Data in Java
Anthony Markham
VP Quant Developer
.selectColumns() creates a new Table object// 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 object// 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().sortDescending() for descending order// 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();
| Mean [Salary] | Count [Salary] | Max [Salary] |
|---|---|---|
| 113606.20299999935 | 1000 | 199793 |
// Multiple aggregations
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() - Choose specific columnsTable selected = employees.select("Name", "Salary");
.where() - Filter rows based on conditionsTable filtered = employees.where(condition);
.sortOn() - Order data by columnsTable sorted = employees.sortOn("Department", "Salary");
.summarize() - Compute statisticsTable summary = employees.summarize("Salary", mean, max).apply();
Importing Data in Java