열 타입 다루기
여러분은 기술 교육 스타트업의 제품 카탈로그를 구축하고 있어요. 강좌를 만들기 전에 제품 가격대를 분석해야 합니다. 가격 범위를 이해하면 어떤 제품에 우선순위를 둘지 결정하는 데 도움이 돼요. DoubleColumn처럼 타입이 지정된 열을 사용하면 일반 열에서는 사용할 수 없는 통계 메서드를 활용할 수 있어요.
Table과 DoubleColumn 클래스는 이미 임포트되어 있습니다.
이 연습은 강의의 일부입니다
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());
}
}
}