#C13912. CSV Data Analysis and Filtering

    ID: 43503 Type: Default 1000ms 256MiB

CSV Data Analysis and Filtering

CSV Data Analysis and Filtering

You are given CSV formatted input via standard input. The CSV data will contain a header and one or more rows. The first column is Category (a string) and the second column is Value (a numerical value). Your task is to perform the following operations:

  • Read and parse the CSV input.
  • If the input is empty, output an error message in the format Error: The input data is empty.
  • If the CSV data is invalid (cannot be parsed as expected), output an error message: Error: The input data is invalid.
  • Fill any missing values with 0.
  • Convert the numeric values to floats if necessary.
  • Group the rows by the Category column and compute the mean of the Value column for each group.
  • Filter the groups keeping only those with an average Value > 10.
  • Output the result in CSV format with a header line followed by the qualifying rows, to standard output.

Note: The output should be printed to standard output. In error cases, print only the error message.

The mathematical condition for filtering can be expressed in LaTeX as follows:

\(\bar{x} > 10\)

inputFormat

The input is provided via standard input (stdin) as CSV text. The first line contains the header with two columns Category and Value. Each subsequent line contains a record. For example:

Category,Value
A,12
B,8
A,15
B,7
C,0
C,5

outputFormat

The output is printed to standard output (stdout) as CSV text. The output must contain the same header as the input. It should include only the groups that satisfy the condition average(Value) > 10. For example, given the sample input above, since the group 'A' has an average value of \(\frac{12+15}{2}=13.5\) (which is greater than 10) while the groups 'B' and 'C' do not meet the condition, the output should be:

Category,Value
A,13.5

In case of errors (empty input or invalid CSV), output exactly one error message.

## sample
Category,Value
A,12
B,8
A,15
B,7
C,0
C,5
Category,Value

A,13.5

</p>