โครงสร้างข้อมูลใน Tablesaw

การนำเข้าข้อมูลใน Java

Anthony Markham

VP Quant Developer

โครงสร้างข้อมูลหลัก

  • Table: คอนเทนเนอร์หลัก (คล้าย DataFrame)
Table employees = Table.create("Employees");
  • Column: เก็บค่าที่มีประเภทข้อมูลเดียวกัน
StringColumn nameCol = StringColumn.create("Name");
  • Row: แทนข้อมูลแต่ละรายการ
Row firstRow = employees.row(0);
การนำเข้าข้อมูลใน Java

เมธอดของ Table

String tableName = employees.name();
employees
// Row and column counts
int rowCount = employees.rowCount();
int columnCount = employees.columnCount();
1000
5
การนำเข้าข้อมูลใน Java

ประเภทของคอลัมน์

  • Strong typing = แต่ละคอลัมน์มีประเภทข้อมูลที่ตายตัว
    • ช่วยเพิ่มประสิทธิภาพและดีบักโค้ดได้ง่ายขึ้น
  • ตัวอย่าง:
    • StringColumn - ข้อมูลข้อความ
    • IntColumn, DoubleColumn - ค่าตัวเลข
    • BooleanColumn - ค่า True/False
    • ข้อมูลอนุกรมเวลา:
      • DateColumn - วันที่ตามปฏิทิน (2024-03-05)
      • DateTimeColumn - วันที่และเวลา (2024-03-05T14:32)
การนำเข้าข้อมูลใน Java

การดำเนินการตามประเภทคอลัมน์

  • แต่ละประเภทมีการดำเนินการเฉพาะของตัวเอง
// Using .mean() on DoubleColumn
DoubleColumn salary = employees.column("Salary");
double averageSalary = salary.mean();
การนำเข้าข้อมูลใน Java

การเข้าถึงข้อมูล

// 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");
การนำเข้าข้อมูลใน Java

Selection

  • ชุดของ index แถวที่ตรงตามเงื่อนไข
  • ตัวอย่าง:
    • .isGreaterThan(), .isLessThan()
    • .isEqualTo()
    • .isAfter()

$$

// Create a selection of rows
Selection highEarners = employees.doubleColumn("Salary")
    .isGreaterThan(70000);
การนำเข้าข้อมูลใน Java

การกรองด้วย 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() คืนค่าเป็น table ใหม่
การนำเข้าข้อมูลใน Java

การดำเนินการแบบ Boolean

  • รวม selection ด้วย .and() และ .or()
Selection recentHires = employees.dateColumn("HireDate")
    .isAfter(LocalDate.of(2020, 1, 1));

Selection highPaidRecent = highEarners.and(recentHires);
การนำเข้าข้อมูลใน Java

มาฝึกกันเถอะ!

การนำเข้าข้อมูลใน Java

Preparing Video For Download...