開始使用免費開始

彙總欄位

你需要清理並分析庫存資料,了解高價商品的庫存模式。原始庫存資料常包含無關項目,且需要依類別整理。先過濾出高價品(超過 $5),接著計算正確的總量,並依類別整理。這個清理且彙總後的視圖,有助於找出哪些部門對高階商品的投資最多。

已為你匯入 tablesaw 套件。

本練習屬於課程

使用 Java 進行資料清理

檢視課程

練習說明

  • 找出高價商品(Unit_Price > $5.00)。
  • 計算各類別的 Stock_Quantity 總和。
  • Category 分組顯示結果。

動手互動練習

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

public class GroceryDataAggregation {
    public static void main(String[] args) {
        Table inventory = Table.read().csv("grocery_inventory.csv");

        Table quantityByCategory = inventory
                // Find expensive items (price > $5.00)
                .where(inventory.doubleColumn("Unit_Price").____(5.0))
                // Calculate total stock for each category
                .____("Stock_Quantity", ____)
                // Group results by product category
                .____("Category");

        System.out.println("Total quantity by category:");
        System.out.println(quantityByCategory.first(5));
    }
}
編輯並執行程式碼