开始使用免费开始使用

使用列类型进行操作

您正在为一家技术培训初创公司构建产品目录。在创建课程之前,您需要先分析产品定价——了解价格区间有助于确定优先推广的产品。使用像 DoubleColumn 这样的强类型列,可以调用通用列不具备的统计方法。

TableDoubleColumn 类已为您导入。

本练习是课程的一部分

Java 中的数据导入

查看课程

练习说明

  • "products.csv" 读入到 products 表。
  • 访问 "Price" 列并存入 prices
  • 打印平均价格。

交互式实操练习

通过完成这段示例代码来试试这个练习。

public class ProductCatalog {
    public static void main(String[] args) {
    	try {
          // Load products.csv into the products table
          Table products = Table.____().csv("____");

		  // Access the Price column and store it in prices
          DoubleColumn ____ = products.doubleColumn("____");
          
          // Print the mean price
          System.out.println("Price Stats - Min: $" + prices.min() +
                  ", Max: $" + prices.max() +
                  ", Mean: $" + prices.____());

          System.out.println(products.first(5));
        } catch (Exception e) {
            System.err.println("Error reading CSV files: " + e.getMessage());
        }
    }
}
编辑并运行代码