開始使用免費開始

表格查詢

課程已經上線,學生也完成註冊——做得好!你的最後一個任務,是找出近期註冊且表現優異的學生,作為下一波宣傳活動的亮點。你現在要使用另一個資料集 students.csv,裡面包含所有學生及其成績的資訊。GPA 欄位是他們的成績,EnrollmentDate 欄位是學生註冊課程的日期。

TableSelectionLocalDate 類別都已為你匯入。

本練習屬於課程

Java 中的資料匯入

檢視課程

練習說明

  • 建立 "GPA" 大於 3.5Selection
  • 建立註冊日期在 Jan 1, 2022 之後的 Selection
  • 合併兩個 Selection 物件。
  • 篩選 students 表格。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

public class StudentAnalysis {
    public static void main(String[] args) {
    	try { 
            Table students = Table.read().csv("students.csv");

            // Create a Selection for GPA greater than 3.5
            Selection highGpa = students.doubleColumn("____").____(3.5);

            // Create a Selection for enrollment after Jan 1, 2022
            Selection freshmen = students.dateColumn("EnrollmentDate")
                .____(LocalDate.of(2022, 1, 1));

            // Combine both Selections
            Selection highPerformingFreshmen = highGpa.____(freshmen);
            
            // Filter the students table
            Table featured = students.____(highPerformingFreshmen);
            
            System.out.println("High-performing freshmen:");
            System.out.println(featured.print());
        } catch (Exception e) {
            System.err.println("Error reading CSV files: " + e.getMessage());
        }
    }
}
編輯並執行程式碼