#C12678. Sales Data Analysis
Sales Data Analysis
Sales Data Analysis
You are given sales data in CSV
format where each record represents a sales transaction. Each transaction contains the following fields: Date, Product ID, Quantity Sold, and Sales Amount.
Your task is to process the input data, group the transactions by Product ID and compute the following for each product:
- Total Quantity Sold: \(\sum\text{(Quantity Sold)}\)
- Total Sales Amount: \(\sum\text{(Sales Amount)}\)
- Average Sales Amount per Transaction: \(\frac{\sum\text{(Sales Amount)}}{\text{Number of Transactions}}\)
The results should be output in CSV format with the header:
Product ID,Total_Quantity_Sold,Total_Sales_Amount,Average_Sales_Amount_per_Transaction
Rows must be sorted in ascending order by Product ID
.
inputFormat
The input is provided to stdin
as CSV text. The first line contains the header: Date,Product ID,Quantity Sold,Sales Amount
. Each subsequent line represents a transaction record.
outputFormat
The output should be printed to stdout
as CSV text with the header: Product ID,Total_Quantity_Sold,Total_Sales_Amount,Average_Sales_Amount_per_Transaction
. Each subsequent line contains the computed summary for a product. All numeric values should be displayed in standard decimal format.
Date,Product ID,Quantity Sold,Sales Amount
2023-01-01,1,10,100.0
2023-01-02,2,20,200.0
2023-01-03,1,15,150.0
2023-01-03,3,8,80.0
Product ID,Total_Quantity_Sold,Total_Sales_Amount,Average_Sales_Amount_per_Transaction
1,25,250.0,125.0
2,20,200.0,200.0
3,8,80.0,80.0
</p>