Data structures in Tablesaw

Importing Data in Java

Anthony Markham

VP Quant Developer

Core data structures

  • Table: Primary container (like a DataFrame)
Table employees = Table.create("Employees");
  • Column: Holds values of a consistent type
StringColumn nameCol = StringColumn.create("Name");
  • Row: Represents individual records
Row firstRow = employees.row(0);
Importing Data in Java

Table methods

String tableName = employees.name();
employees
// Row and column counts
int rowCount = employees.rowCount();
int columnCount = employees.columnCount();
1000
5
Importing Data in Java

Column types

  • Strong typing = each column has fixed data type
    • Improves performance and makes code easier to debug
  • Examples:
    • StringColumn - Text data
    • IntColumn, DoubleColumn - Numeric values
    • BooleanColumn - True/False values
    • Time series data:
      • DateColumn - calendar dates (2024-03-05)
      • DateTimeColumn - datetime (2024-03-05T14:32)
Importing Data in Java

Column type operations

  • Each type provides specialized operations
// Using .mean() on DoubleColumn
DoubleColumn salary = employees.column("Salary");
double averageSalary = salary.mean();
Importing Data in Java

Accessing data

// Get a specific column
StringColumn names = employees.stringColumn("Name");

// Get a general column names = employees.column("Name");
// Get a value from a column String firstPerson = names.get(0);
// Get an entire row Row firstRow = employees.row(0);
// Get a value from a row double salary = firstRow.getDouble("Salary");
Importing Data in Java

Selections

  • Set of row indices that match a condition
  • Examples:
    • .isGreaterThan(), .isLessThan()
    • .isEqualTo()
    • .isAfter()

$$

// Create a selection of rows
Selection highEarners = employees.doubleColumn("Salary")
    .isGreaterThan(70000);
Importing Data in Java

Filtering on a Selection

// Create a selection of rows
Selection highEarners = employees.doubleColumn("Salary")
    .isGreaterThan(70000);


// Apply selection to get a filtered table Table highPaidEmployees = employees.where(highEarners);

$$

$$

  • .where() returns a new table
Importing Data in Java

Boolean operations

  • Combine selections with .and() and .or()
Selection recentHires = employees.dateColumn("HireDate")
    .isAfter(LocalDate.of(2020, 1, 1));

Selection highPaidRecent = highEarners.and(recentHires);
Importing Data in Java

Let's practice!

Importing Data in Java

Preparing Video For Download...