#C260. E-Commerce Data Analysis

    ID: 45934 Type: Default 1000ms 256MiB

E-Commerce Data Analysis

E-Commerce Data Analysis

You are given CSV formatted data via standard input containing e-commerce product details. The CSV has four columns: product_id, category, price, and rating. Your task is to process this data as follows:

  1. Ignore any row with missing values.
  2. For each category, compute the average price of products. The average should be rounded to two decimal places.
  3. For each category, identify the product with the highest rating.
  4. Merge these results and output a CSV with columns: category, price (average price), product_id (the product with the highest rating), and rating (its rating).

The output must be printed to standard output and include a header row. The rows should be sorted in lexicographical order based on the category.

inputFormat

The input is provided on standard input. The first line is a CSV header:

product_id,category,price,rating

Each subsequent line represents a product record. Values in each row are separated by commas.

outputFormat

Output the processed data as a CSV to standard output with a header:

category,price,product_id,rating

For each category (sorted lexicographically), output a line where 'price' is the average price (formatted to two decimal places) and 'product_id' with its 'rating' corresponds to the product with the highest rating in that category.## sample

product_id,category,price,rating
1,Electronics,199.99,4.5
2,Electronics,299.99,5.0
3,Books,10.99,4.0
4,Books,15.99,4.5
category,price,product_id,rating

Books,13.49,4,4.5 Electronics,249.99,2,5.0

</p>