#C14834. Titanic Data Analysis
Titanic Data Analysis
Titanic Data Analysis
You are given a Titanic dataset in CSV format through standard input. The dataset contains records of passengers with their age, sex, survival status, and ticket class. Your task is to analyze the dataset and compute the following metrics:
- The average age of all passengers, rounded to one decimal place.
- The survival rate for each gender (Male and Female) as a percentage with one decimal (i.e. $\text{Survival Rate} = \frac{\text{number of survivors}}{\text{total number in group}} \times 100$).
- The survival rate for each ticket class (1, 2, and 3) as a percentage with one decimal.
You must then output exactly six lines in the following format:
Average Age: <average_age> Female Survival Rate: <female_rate>% Male Survival Rate: <male_rate>% Class 1 Survival Rate: % Class 2 Survival Rate: % Class 3 Survival Rate: %
Ensure that if a particular group has no entries, its survival rate is output as 0.0%.
inputFormat
The input is provided via standard input in CSV format. The first line is the header with the following columns:
Age,Sex,Survived,Pclass
Each subsequent line contains data for one passenger. The fields are:
- Age: a floating-point number representing the age of the passenger.
- Sex: either 'Male' or 'Female'.
- Survived: an integer (0 or 1), where 1 indicates the passenger survived.
- Pclass: an integer (1, 2, or 3) representing the ticket class.
There will be at least one data row.
outputFormat
Print exactly six lines to standard output as follows:
Line 1: Average Age: <average_age> Line 2: Female Survival Rate: <female_rate>% Line 3: Male Survival Rate: <male_rate>% Line 4: Class 1 Survival Rate: % Line 5: Class 2 Survival Rate: % Line 6: Class 3 Survival Rate: %
The average age should be rounded to one decimal place. Each survival rate is computed as (\frac{\text{number of survivors}}{\text{total in group}} \times 100) and rounded to one decimal place. If a group has no entries, output 0.0% for that group.## sample
Age,Sex,Survived,Pclass
22,Male,0,3
38,Female,1,1
26,Female,1,3
35,Male,0,1
Average Age: 30.3
Female Survival Rate: 100.0%
Male Survival Rate: 0.0%
Class 1 Survival Rate: 50.0%
Class 2 Survival Rate: 0.0%
Class 3 Survival Rate: 50.0%
</p>