DataLeaguebeta

Project

Titanic passengers: mean, median and quartiles

Who travelled on the Titanic and how much did they pay? Measures of location by class, port and sex for 891 real passengers.

10 steps~45 min180 points in total

The list of 891 passengers of the Titanic from April 1912 is one of the best-known teaching datasets. In this project you will use it to describe the typical passenger: how old they were, how much they paid for a ticket and how this differed between classes, ports and sexes. You will learn to choose the right measure of location, compare groups with groupby and read what the difference between the mean and the median reveals.

Each step is a separate task with a check and hints. The code steps already have the data loaded, so a mistake in one step does not spoil the next ones.

Data

The file titanic.csv: semicolon separator, decimal point, an empty cell means a missing value. One row is one passenger. The column names and categories are in Slovak and stay that way in the code.

columnmeaningvalues
prezilsurvived the sinkingáno (yes), nie (no)
triedatravel class1 (most expensive), 2, 3
pohlaviesexmuž (man), žena (woman)
vekage in years (children under one year have a fraction, estimates end in a half, e.g. 28.5)years, missing for 177 passengers
surodenci_partnernumber of siblings and spouses on boardnumber of people
rodicia_detinumber of parents and children on boardnumber of people
cestovneticket fare (a ticket could cover several people)pounds
pristavport of embarkationCherbourg, Queenstown, Southampton
palubacabin deckA to G, mostly missing
samtravelled without familyáno (yes), nie (no)

Source: the public passenger list of the Titanic in the version from the sample data of the seaborn library. The column names and categories are translated into Slovak, the values are original.

Data

titanic.csv891 rows, 10 columns

Download CSV
First 5 rows of the file
preziltriedapohlavieveksurodenci_partnerrodicia_deticestovnepristavpalubasam
nie3muž22.0107.25SouthamptonNaNnie
áno1žena38.01071.2833CherbourgCnie
áno3žena26.0007.925SouthamptonNaNáno
áno1žena35.01053.1SouthamptonCnie
nie3muž35.0008.05SouthamptonNaNáno

Steps

The steps build on each other. In code steps the data and the results of earlier steps are already prepared.

  1. Step 1

    Age of the passengers

    code20 pts
    pandasmeanmedianmodemissing values

    Describe the age of the passengers (column vek). The table df is already loaded.

    1. Store the number of passengers with known age in n_vek and the proportion of passengers whose age is missing in podiel_chyba.
    2. Store the mean, median and mode of age in priemer_vek, median_vek and modus_vek (the mode as a single number).
    Python loads when you first use the editorPackages:pandas

    The output appears after you run the code.

    Run the code and fix the errors until all checks pass.

  2. Step 2

    How many were children

    number15 pts
    relative frequencymissing valuesfiltering

    A colleague ran:

    >>> (df["vek"] < 18).sum()
    113
    >>> len(df)
    891
    

    What percentage of the passengers with known age were younger than 18? Enter it to one decimal place. You will find the other number you need in the previous step.

    %

    Both a decimal point and a decimal comma are accepted.

  3. Step 3

    Age by class

    code20 pts
    pandasgroupbymeanmedian

    Compare the age of the passengers in the individual classes (column trieda).

    Store in vek_trieda a table that contains, for each class, the mean, the median and the number of known ages (columns mean, median, count).

    Python loads when you first use the editorPackages:pandas

    The output appears after you run the code.

    Run the code and fix the errors until all checks pass.

  4. Step 4

    What is true about age in the classes

    choice15 pts
    mediancomparing groupsinterpretation

    The result of the previous step:

    classmeanmedianknown ages
    138.2337186
    229.8829173
    325.1424355

    Which statement is correct?

    Pick one option.
  5. Step 5

    Fare by port

    code25 pts
    pandasgroupbymeanmedianoutliers

    Compare the ticket fare (cestovne) by the port where the passenger boarded (pristav).

    1. Store the mean, median and count of the fare for each port in cestovne_pristav (columns mean, median, count).
    2. Store the difference between the mean and the median for each port in rozdiel.
    3. Store the name of the port where this difference is the largest in najvacsi.
    Python loads when you first use the editorPackages:pandas

    The output appears after you run the code.

    Run the code and fix the errors until all checks pass.

  6. Step 6

    Why the mean is twice as high

    choice15 pts
    meanmedianshape of distribution

    In Cherbourg the mean fare is 59.95 pounds, but the median is only 29.70 pounds.

    What follows from this?

    Pick one option.
  7. Step 7

    Quartiles of age for men and women

    code20 pts
    pandasquartilespercentilesgroupby

    Compare the distribution of age for men and women using quartiles.

    1. Store a table with the lower quartile, median and upper quartile of age for men and women in kvartily (rows muž (men) and žena (women), columns 0.25, 0.5, 0.75).
    2. Store the 90th percentile of the age of all passengers in p90.
    Python loads when you first use the editorPackages:pandas

    The output appears after you run the code.

    Run the code and fix the errors until all checks pass.

  8. Step 8

    The typical ticket in 2nd class

    number10 pts
    mediangroupby

    A colleague ran:

    >>> df.groupby("trieda")["cestovne"].agg(["mean", "median"]).round(2)
             mean  median
    trieda
    1       84.15   60.29
    2       20.66   14.25
    3       13.68    8.05
    

    What is the median fare in 2nd class in pounds? Enter it to two decimal places.

    pounds

    Both a decimal point and a decimal comma are accepted.

  9. Step 9

    Which measure for class

    choice15 pts
    ordinal variablemedianmodemeasurement scales

    The variable trieda (class) has the values 1, 2 and 3. Pandas computes for it:

    >>> df["trieda"].mean(), df["trieda"].median(), df["trieda"].mode()[0]
    (2.308641975308642, 3.0, 3)
    

    Which sentence about the passengers by class makes sense?

    Pick one option.
  10. Step 10

    The typical passenger by class

    text25 pts
    interpretationmedianmeancomparing groups

    Write a short paragraph (4 to 7 sentences) for a museum guide: what the typical passenger was like in 1st, 2nd and 3rd class in terms of age and ticket price. Give specific numbers from this project, justify which measure of location you chose, and mention what to watch out for with these numbers.

    0 words, minimum 5050 words to go