分析遺漏值與唯一值
身為雜貨庫存分析師,你需要評估新庫存追蹤系統的資料品質。在分析庫存量與定價之前,你要先檢查是否有遺漏值,並確認商品分類是否正確。載入庫存資料,檢查每個欄位的完整性,並分析分類的分佈情形。以下是部分範例資料:
| Product_Name | Category | Date_Received | Stock_Quantity | Unit_Price |
|---|---|---|---|---|
| Bell Pepper | Fruits & Vegetables | 3/1/24 | 46 | 4.6 |
| Vegetable Oil | Oils & Fats | 4/1/24 | 51 | 2 |
| Parmesan Cheese | Dairy | 4/1/24 | 38 | 12 |
已為你匯入 tablesaw 套件。
本練習屬於課程
使用 Java 進行資料清理
練習說明
- 從
inventory取出欄位,並計算該欄位的遺漏值數量。 - 依唯一的分類統計
inventory的筆數。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
public class GroceryDataQuality {
public static void main(String[] args) {
Table inventory = Table.read().csv("grocery_inventory.csv");
for (String colName : inventory.columnNames()) {
// Extract the column and count missing values in the column
int missing = inventory.____(colName).____();
System.out.println(colName + " missing values: " + missing);
}
// Count the inventory by unique categories
Table catCounts = ____.____("Category");
System.out.println("\nCategory distribution:");
System.out.println(catCounts);
}
}