{ "cells": [ { "cell_type": "markdown", "id": "93fda237-0977-46c0-8035-a2f8f06d61fb", "metadata": { "tags": [] }, "source": [ "# Tutorial Exercises 1: Probability Jargon in Python\n", "\n", "In this section we will revise the terms for combinations of events and how they relate to frequencies in a `pandas` dataframe.\n", "\n", "You should be able to answer the following questions with the help of the `pandas` function `query` (to find the rows matching some criterion) and the function `len()`, which finds the length of the dataframe within the parentheses.\n", "\n" ] }, { "cell_type": "markdown", "id": "1f6ca970-bb56-4098-8d3e-4dbcb15deaaa", "metadata": {}, "source": [ "### Set up Python libraries\n", "\n", "As usual, run the code cell below to import the relevant Python libraries" ] }, { "cell_type": "code", "execution_count": null, "id": "5912aa02-3e45-4e81-9a26-a45334c31c26", "metadata": {}, "outputs": [], "source": [ "# Set-up Python libraries - you need to run this but you don't need to change it\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import scipy.stats as stats\n", "import pandas as pd\n", "import seaborn as sns\n", "sns.set_theme(style='white')\n", "import statsmodels.api as sm\n", "import statsmodels.formula.api as smf" ] }, { "cell_type": "markdown", "id": "a5c7b791-2ea1-4d77-8f0b-1ce77c719e81", "metadata": {}, "source": [ "## Event combinations\n", "\n", "Let's work with the (made up) data on students from Beaufort and Lonsdale college." ] }, { "cell_type": "code", "execution_count": 15, "id": "d8a2688f-6f39-488a-b53a-fd4f1535e430", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
\n", " | ID_code | \n", "College | \n", "Subject | \n", "Score_preVac | \n", "Score_postVac | \n", "
---|---|---|---|---|---|
0 | \n", "247610 | \n", "Lonsdale | \n", "PPE | \n", "60 | \n", "35 | \n", "
1 | \n", "448590 | \n", "Lonsdale | \n", "PPE | \n", "43 | \n", "44 | \n", "
2 | \n", "491100 | \n", "Lonsdale | \n", "engineering | \n", "79 | \n", "69 | \n", "
3 | \n", "316150 | \n", "Lonsdale | \n", "PPE | \n", "55 | \n", "61 | \n", "
4 | \n", "251870 | \n", "Lonsdale | \n", "engineering | \n", "62 | \n", "65 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
296 | \n", "440570 | \n", "Beaufort | \n", "history | \n", "75 | \n", "70 | \n", "
297 | \n", "826030 | \n", "Beaufort | \n", "maths | \n", "52 | \n", "49 | \n", "
298 | \n", "856260 | \n", "Beaufort | \n", "Biology | \n", "83 | \n", "84 | \n", "
299 | \n", "947060 | \n", "Beaufort | \n", "engineering | \n", "62 | \n", "65 | \n", "
300 | \n", "165780 | \n", "Beaufort | \n", "PPE | \n", "48 | \n", "56 | \n", "
301 rows × 5 columns
\n", "