테이블 필터링
기본 상품 카탈로그를 불러왔으니, 이제 스타트업에서는 고급 교육 과정을 위해 프리미엄 상품에 집중하려고 해요. 어떤 상품이 "프리미엄"(가격이 $800 초과)인지 식별하고, 마케팅 팀을 위한 필터링된 데이터셋을 만들어야 해요.
Table, DoubleColumn, Selection 클래스는 이미 임포트되어 있어요.
이 연습은 강의의 일부입니다
Java에서 데이터 가져오기
연습 안내
"Price"가800보다 큰 항목에 대한Selection을 생성하세요.- 만든
Selection으로 products 테이블을 필터링하세요. - 프리미엄 상품의 행 개수를 출력하세요.
- 프리미엄 상품의 평균 가격을 출력하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
public class ProductCatalog {
public static void main(String[] args) {
try {
Table products = Table.read().csv("products.csv");
// Create a Selection for Price greater than 800
Selection premiumSelection = products.doubleColumn("Price")
.____(____);
// Filter the products table using the Selection
Table premiumProducts = products.____(____);
// Print the row count of premium products
System.out.println("Number of premium products: " + premiumProducts.____());
// Print the mean price of premium products
DoubleColumn premiumPrices = premiumProducts.doubleColumn("Price");
System.out.println("Average price of premium products: $" + premiumPrices.____());
} catch (Exception e) {
System.err.println("Error reading CSV files: " + e.getMessage());
}
}
}