{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "This is practice related to the Logic and Control section of the Datacamp course Intermediate Python for Data Science\n", "\n", "Much of what we need to know is rooted in common sense. For example, Suppose our friend Sally says *Ann went to the party*. If we saw pictures of the party and Ann was indeed there we would say that Sally is telling the truth ... or we would say her statement *Ann went to the party* is true. As English-speakers we also know the meaning of 'and' and 'or'. So if Sally said to us:\n", "\n", "> *I will go to the party if Ann and Jane go, or if you go*\n", "\n", "If we told Sally that we would go then she would be truthful if she went as well, and we would say she lied (or her statement was false) if she said she still wasn't going to the party. Here's a question:\n", "\n", "> *Suppose Sally didn't go to the party; Ann went to the party; and Jane did not go. Is the above statement true or false?*\n", "\n", "In the DataCamp course we learned how we can express these conditionals in Python. For example:\n", "\n", " if ann == 'yes' and jane == 'yes':\n", " print('I will go to the party')\n", " else:\n", " print('I will not go to the party')\n", "\n", "This rudiment gives us some practice with this.\n", "\n", "# Titanic\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We are going to work with a data set of the passengers of the Titanic. Let's load it in and take a look at it." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | Survived | \n", "Pclass | \n", "Name | \n", "Sex | \n", "Age | \n", "SibSp | \n", "Parch | \n", "Ticket | \n", "Fare | \n", "Cabin | \n", "Embarked | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|
PassengerId | \n", "\n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " |
1 | \n", "0 | \n", "3 | \n", "Braund, Mr. Owen Harris | \n", "male | \n", "22.0 | \n", "1 | \n", "0 | \n", "A/5 21171 | \n", "7.2500 | \n", "NaN | \n", "S | \n", "
2 | \n", "1 | \n", "1 | \n", "Cumings, Mrs. John Bradley (Florence Briggs Th... | \n", "female | \n", "38.0 | \n", "1 | \n", "0 | \n", "PC 17599 | \n", "71.2833 | \n", "C85 | \n", "C | \n", "
3 | \n", "1 | \n", "3 | \n", "Heikkinen, Miss. Laina | \n", "female | \n", "26.0 | \n", "0 | \n", "0 | \n", "STON/O2. 3101282 | \n", "7.9250 | \n", "NaN | \n", "S | \n", "
4 | \n", "1 | \n", "1 | \n", "Futrelle, Mrs. Jacques Heath (Lily May Peel) | \n", "female | \n", "35.0 | \n", "1 | \n", "0 | \n", "113803 | \n", "53.1000 | \n", "C123 | \n", "S | \n", "
5 | \n", "0 | \n", "3 | \n", "Allen, Mr. William Henry | \n", "male | \n", "35.0 | \n", "0 | \n", "0 | \n", "373450 | \n", "8.0500 | \n", "NaN | \n", "S | \n", "
6 | \n", "0 | \n", "3 | \n", "Moran, Mr. James | \n", "male | \n", "NaN | \n", "0 | \n", "0 | \n", "330877 | \n", "8.4583 | \n", "NaN | \n", "Q | \n", "
7 | \n", "0 | \n", "1 | \n", "McCarthy, Mr. Timothy J | \n", "male | \n", "54.0 | \n", "0 | \n", "0 | \n", "17463 | \n", "51.8625 | \n", "E46 | \n", "S | \n", "
8 | \n", "0 | \n", "3 | \n", "Palsson, Master. Gosta Leonard | \n", "male | \n", "2.0 | \n", "3 | \n", "1 | \n", "349909 | \n", "21.0750 | \n", "NaN | \n", "S | \n", "
9 | \n", "1 | \n", "3 | \n", "Johnson, Mrs. Oscar W (Elisabeth Vilhelmina Berg) | \n", "female | \n", "27.0 | \n", "0 | \n", "2 | \n", "347742 | \n", "11.1333 | \n", "NaN | \n", "S | \n", "
10 | \n", "1 | \n", "2 | \n", "Nasser, Mrs. Nicholas (Adele Achem) | \n", "female | \n", "14.0 | \n", "1 | \n", "0 | \n", "237736 | \n", "30.0708 | \n", "NaN | \n", "C | \n", "
11 | \n", "1 | \n", "3 | \n", "Sandstrom, Miss. Marguerite Rut | \n", "female | \n", "4.0 | \n", "1 | \n", "1 | \n", "PP 9549 | \n", "16.7000 | \n", "G6 | \n", "S | \n", "
12 | \n", "1 | \n", "1 | \n", "Bonnell, Miss. Elizabeth | \n", "female | \n", "58.0 | \n", "0 | \n", "0 | \n", "113783 | \n", "26.5500 | \n", "C103 | \n", "S | \n", "
13 | \n", "0 | \n", "3 | \n", "Saundercock, Mr. William Henry | \n", "male | \n", "20.0 | \n", "0 | \n", "0 | \n", "A/5. 2151 | \n", "8.0500 | \n", "NaN | \n", "S | \n", "
14 | \n", "0 | \n", "3 | \n", "Andersson, Mr. Anders Johan | \n", "male | \n", "39.0 | \n", "1 | \n", "5 | \n", "347082 | \n", "31.2750 | \n", "NaN | \n", "S | \n", "
15 | \n", "0 | \n", "3 | \n", "Vestrom, Miss. Hulda Amanda Adolfina | \n", "female | \n", "14.0 | \n", "0 | \n", "0 | \n", "350406 | \n", "7.8542 | \n", "NaN | \n", "S | \n", "
16 | \n", "1 | \n", "2 | \n", "Hewlett, Mrs. (Mary D Kingcome) | \n", "female | \n", "55.0 | \n", "0 | \n", "0 | \n", "248706 | \n", "16.0000 | \n", "NaN | \n", "S | \n", "
17 | \n", "0 | \n", "3 | \n", "Rice, Master. Eugene | \n", "male | \n", "2.0 | \n", "4 | \n", "1 | \n", "382652 | \n", "29.1250 | \n", "NaN | \n", "Q | \n", "
18 | \n", "1 | \n", "2 | \n", "Williams, Mr. Charles Eugene | \n", "male | \n", "NaN | \n", "0 | \n", "0 | \n", "244373 | \n", "13.0000 | \n", "NaN | \n", "S | \n", "
19 | \n", "0 | \n", "3 | \n", "Vander Planke, Mrs. Julius (Emelia Maria Vande... | \n", "female | \n", "31.0 | \n", "1 | \n", "0 | \n", "345763 | \n", "18.0000 | \n", "NaN | \n", "S | \n", "
20 | \n", "1 | \n", "3 | \n", "Masselmani, Mrs. Fatima | \n", "female | \n", "NaN | \n", "0 | \n", "0 | \n", "2649 | \n", "7.2250 | \n", "NaN | \n", "C | \n", "
21 | \n", "0 | \n", "2 | \n", "Fynney, Mr. Joseph J | \n", "male | \n", "35.0 | \n", "0 | \n", "0 | \n", "239865 | \n", "26.0000 | \n", "NaN | \n", "S | \n", "
22 | \n", "1 | \n", "2 | \n", "Beesley, Mr. Lawrence | \n", "male | \n", "34.0 | \n", "0 | \n", "0 | \n", "248698 | \n", "13.0000 | \n", "D56 | \n", "S | \n", "
23 | \n", "1 | \n", "3 | \n", "McGowan, Miss. Anna \"Annie\" | \n", "female | \n", "15.0 | \n", "0 | \n", "0 | \n", "330923 | \n", "8.0292 | \n", "NaN | \n", "Q | \n", "
24 | \n", "1 | \n", "1 | \n", "Sloper, Mr. William Thompson | \n", "male | \n", "28.0 | \n", "0 | \n", "0 | \n", "113788 | \n", "35.5000 | \n", "A6 | \n", "S | \n", "
25 | \n", "0 | \n", "3 | \n", "Palsson, Miss. Torborg Danira | \n", "female | \n", "8.0 | \n", "3 | \n", "1 | \n", "349909 | \n", "21.0750 | \n", "NaN | \n", "S | \n", "
26 | \n", "1 | \n", "3 | \n", "Asplund, Mrs. Carl Oscar (Selma Augusta Emilia... | \n", "female | \n", "38.0 | \n", "1 | \n", "5 | \n", "347077 | \n", "31.3875 | \n", "NaN | \n", "S | \n", "
27 | \n", "0 | \n", "3 | \n", "Emir, Mr. Farred Chehab | \n", "male | \n", "NaN | \n", "0 | \n", "0 | \n", "2631 | \n", "7.2250 | \n", "NaN | \n", "C | \n", "
28 | \n", "0 | \n", "1 | \n", "Fortune, Mr. Charles Alexander | \n", "male | \n", "19.0 | \n", "3 | \n", "2 | \n", "19950 | \n", "263.0000 | \n", "C23 C25 C27 | \n", "S | \n", "
29 | \n", "1 | \n", "3 | \n", "O'Dwyer, Miss. Ellen \"Nellie\" | \n", "female | \n", "NaN | \n", "0 | \n", "0 | \n", "330959 | \n", "7.8792 | \n", "NaN | \n", "Q | \n", "
30 | \n", "0 | \n", "3 | \n", "Todoroff, Mr. Lalio | \n", "male | \n", "NaN | \n", "0 | \n", "0 | \n", "349216 | \n", "7.8958 | \n", "NaN | \n", "S | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
862 | \n", "0 | \n", "2 | \n", "Giles, Mr. Frederick Edward | \n", "male | \n", "21.0 | \n", "1 | \n", "0 | \n", "28134 | \n", "11.5000 | \n", "NaN | \n", "S | \n", "
863 | \n", "1 | \n", "1 | \n", "Swift, Mrs. Frederick Joel (Margaret Welles Ba... | \n", "female | \n", "48.0 | \n", "0 | \n", "0 | \n", "17466 | \n", "25.9292 | \n", "D17 | \n", "S | \n", "
864 | \n", "0 | \n", "3 | \n", "Sage, Miss. Dorothy Edith \"Dolly\" | \n", "female | \n", "NaN | \n", "8 | \n", "2 | \n", "CA. 2343 | \n", "69.5500 | \n", "NaN | \n", "S | \n", "
865 | \n", "0 | \n", "2 | \n", "Gill, Mr. John William | \n", "male | \n", "24.0 | \n", "0 | \n", "0 | \n", "233866 | \n", "13.0000 | \n", "NaN | \n", "S | \n", "
866 | \n", "1 | \n", "2 | \n", "Bystrom, Mrs. (Karolina) | \n", "female | \n", "42.0 | \n", "0 | \n", "0 | \n", "236852 | \n", "13.0000 | \n", "NaN | \n", "S | \n", "
867 | \n", "1 | \n", "2 | \n", "Duran y More, Miss. Asuncion | \n", "female | \n", "27.0 | \n", "1 | \n", "0 | \n", "SC/PARIS 2149 | \n", "13.8583 | \n", "NaN | \n", "C | \n", "
868 | \n", "0 | \n", "1 | \n", "Roebling, Mr. Washington Augustus II | \n", "male | \n", "31.0 | \n", "0 | \n", "0 | \n", "PC 17590 | \n", "50.4958 | \n", "A24 | \n", "S | \n", "
869 | \n", "0 | \n", "3 | \n", "van Melkebeke, Mr. Philemon | \n", "male | \n", "NaN | \n", "0 | \n", "0 | \n", "345777 | \n", "9.5000 | \n", "NaN | \n", "S | \n", "
870 | \n", "1 | \n", "3 | \n", "Johnson, Master. Harold Theodor | \n", "male | \n", "4.0 | \n", "1 | \n", "1 | \n", "347742 | \n", "11.1333 | \n", "NaN | \n", "S | \n", "
871 | \n", "0 | \n", "3 | \n", "Balkic, Mr. Cerin | \n", "male | \n", "26.0 | \n", "0 | \n", "0 | \n", "349248 | \n", "7.8958 | \n", "NaN | \n", "S | \n", "
872 | \n", "1 | \n", "1 | \n", "Beckwith, Mrs. Richard Leonard (Sallie Monypeny) | \n", "female | \n", "47.0 | \n", "1 | \n", "1 | \n", "11751 | \n", "52.5542 | \n", "D35 | \n", "S | \n", "
873 | \n", "0 | \n", "1 | \n", "Carlsson, Mr. Frans Olof | \n", "male | \n", "33.0 | \n", "0 | \n", "0 | \n", "695 | \n", "5.0000 | \n", "B51 B53 B55 | \n", "S | \n", "
874 | \n", "0 | \n", "3 | \n", "Vander Cruyssen, Mr. Victor | \n", "male | \n", "47.0 | \n", "0 | \n", "0 | \n", "345765 | \n", "9.0000 | \n", "NaN | \n", "S | \n", "
875 | \n", "1 | \n", "2 | \n", "Abelson, Mrs. Samuel (Hannah Wizosky) | \n", "female | \n", "28.0 | \n", "1 | \n", "0 | \n", "P/PP 3381 | \n", "24.0000 | \n", "NaN | \n", "C | \n", "
876 | \n", "1 | \n", "3 | \n", "Najib, Miss. Adele Kiamie \"Jane\" | \n", "female | \n", "15.0 | \n", "0 | \n", "0 | \n", "2667 | \n", "7.2250 | \n", "NaN | \n", "C | \n", "
877 | \n", "0 | \n", "3 | \n", "Gustafsson, Mr. Alfred Ossian | \n", "male | \n", "20.0 | \n", "0 | \n", "0 | \n", "7534 | \n", "9.8458 | \n", "NaN | \n", "S | \n", "
878 | \n", "0 | \n", "3 | \n", "Petroff, Mr. Nedelio | \n", "male | \n", "19.0 | \n", "0 | \n", "0 | \n", "349212 | \n", "7.8958 | \n", "NaN | \n", "S | \n", "
879 | \n", "0 | \n", "3 | \n", "Laleff, Mr. Kristo | \n", "male | \n", "NaN | \n", "0 | \n", "0 | \n", "349217 | \n", "7.8958 | \n", "NaN | \n", "S | \n", "
880 | \n", "1 | \n", "1 | \n", "Potter, Mrs. Thomas Jr (Lily Alexenia Wilson) | \n", "female | \n", "56.0 | \n", "0 | \n", "1 | \n", "11767 | \n", "83.1583 | \n", "C50 | \n", "C | \n", "
881 | \n", "1 | \n", "2 | \n", "Shelley, Mrs. William (Imanita Parrish Hall) | \n", "female | \n", "25.0 | \n", "0 | \n", "1 | \n", "230433 | \n", "26.0000 | \n", "NaN | \n", "S | \n", "
882 | \n", "0 | \n", "3 | \n", "Markun, Mr. Johann | \n", "male | \n", "33.0 | \n", "0 | \n", "0 | \n", "349257 | \n", "7.8958 | \n", "NaN | \n", "S | \n", "
883 | \n", "0 | \n", "3 | \n", "Dahlberg, Miss. Gerda Ulrika | \n", "female | \n", "22.0 | \n", "0 | \n", "0 | \n", "7552 | \n", "10.5167 | \n", "NaN | \n", "S | \n", "
884 | \n", "0 | \n", "2 | \n", "Banfield, Mr. Frederick James | \n", "male | \n", "28.0 | \n", "0 | \n", "0 | \n", "C.A./SOTON 34068 | \n", "10.5000 | \n", "NaN | \n", "S | \n", "
885 | \n", "0 | \n", "3 | \n", "Sutehall, Mr. Henry Jr | \n", "male | \n", "25.0 | \n", "0 | \n", "0 | \n", "SOTON/OQ 392076 | \n", "7.0500 | \n", "NaN | \n", "S | \n", "
886 | \n", "0 | \n", "3 | \n", "Rice, Mrs. William (Margaret Norton) | \n", "female | \n", "39.0 | \n", "0 | \n", "5 | \n", "382652 | \n", "29.1250 | \n", "NaN | \n", "Q | \n", "
887 | \n", "0 | \n", "2 | \n", "Montvila, Rev. Juozas | \n", "male | \n", "27.0 | \n", "0 | \n", "0 | \n", "211536 | \n", "13.0000 | \n", "NaN | \n", "S | \n", "
888 | \n", "1 | \n", "1 | \n", "Graham, Miss. Margaret Edith | \n", "female | \n", "19.0 | \n", "0 | \n", "0 | \n", "112053 | \n", "30.0000 | \n", "B42 | \n", "S | \n", "
889 | \n", "0 | \n", "3 | \n", "Johnston, Miss. Catherine Helen \"Carrie\" | \n", "female | \n", "NaN | \n", "1 | \n", "2 | \n", "W./C. 6607 | \n", "23.4500 | \n", "NaN | \n", "S | \n", "
890 | \n", "1 | \n", "1 | \n", "Behr, Mr. Karl Howell | \n", "male | \n", "26.0 | \n", "0 | \n", "0 | \n", "111369 | \n", "30.0000 | \n", "C148 | \n", "C | \n", "
891 | \n", "0 | \n", "3 | \n", "Dooley, Mr. Patrick | \n", "male | \n", "32.0 | \n", "0 | \n", "0 | \n", "370376 | \n", "7.7500 | \n", "NaN | \n", "Q | \n", "
891 rows × 11 columns
\n", "