开始使用免费开始使用

分析缺失值与唯一值

作为一名杂货库存分析师,您需要评估新库存追踪系统中的数据质量。在分析库存水平和定价之前,先检查是否存在缺失数据,并核实产品的分类是否正确。加载库存数据,检查每一列的完整性,并分析类别分布。部分示例数据如下所示。

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);
    }
}
编辑并运行代码