시작하기무료로 시작하기

JSON 데이터 분석

제품 카탈로그가 로드되었으니, 마케팅 팀에서 가격 보고서를 요청했습니다. 평균 가격, 가장 비싼 제품, 그리고 카테고리별 제품 분포를 알고 싶어 합니다.

좋은 소식이 있어요. JSON 데이터를 Tablesaw 테이블로 읽어들이면, 이미 알고 있는 동일한 열 연산을 그대로 사용할 수 있습니다.

JsonReader, JsonReadOptions, Table 클래스가 임포트되어 있고, products.json 파일에는 name, price, category 열이 들어 있습니다.

이 연습은 강의의 일부입니다

Java에서 데이터 가져오기

강의 보기

연습 안내

  • JSON 읽기 코드를 완성해 products 테이블을 로드하세요.
  • 열 메서드를 사용해 평균 가격을 계산하세요.
  • 데이터셋에서 최대 가격을 찾으세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

public class JSONAnalysis {
    public static void main(String[] args) {
        // Complete the JSON read
        JsonReadOptions options = JsonReadOptions.builder("products.json").build();
        Table products = new JsonReader().____(options);
        
        // Calculate average price
        double avgPrice = products.doubleColumn("price").____();
        
        // Find maximum price
        DoubleColumn priceCol = products.doubleColumn("price");
        double maxPrice = ____.____();
        String mostExpensive = products
            .where(priceCol.isEqualTo(maxPrice))
            .stringColumn("name").get(0);
        
        Table categoryCount = products.countBy("category");
        System.out.println("Product Analytics Report:");
        System.out.println("========================");
        System.out.printf("Average Price: $%.2f%n", avgPrice);
        System.out.println("Most Expensive: " + mostExpensive + " ($" + maxPrice + ")");
        System.out.println("\nCategory Distribution:");
        System.out.println(categoryCount.print());
    }
}
코드 편집 및 실행