Data manipulation and analysis

Importing Data in Java

Anthony Markham

VP Quant Developer

Column selection

  • .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));
Importing Data in Java

Filtering data

  • Filter rows with .where()
  • Returns a new 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)));
Importing Data in Java

Sorting data

  • Organize data with .sortOn()
    • Sorts in ascending order
  • Returns a new sorted table
  • .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");
Importing Data in Java

Aggregation with summarize

  • Compute summary statistics with .summarize()
  • Returns a new table
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
  • Applies to all numeric columns by default
Importing Data in Java

Aggregation with summarize

  • More complex aggregations are possible
// 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
Importing Data in Java

Core manipulation methods

  • .select() - Choose specific columns
    Table selected = employees.select("Name", "Salary");
    
  • .where() - Filter rows based on conditions
    Table filtered = employees.where(condition);
    
  • .sortOn() - Order data by columns
    Table sorted = employees.sortOn("Department", "Salary");
    
  • .summarize() - Compute statistics
    Table summary = employees.summarize("Salary", mean, max).apply();
    
Importing Data in Java

Let's practice!

Importing Data in Java

Preparing Video For Download...