// Numbas version: finer_feedback_settings {"name": "Python - Basketball players", "extensions": ["stats", "programming", "random_person", "download-text-file"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"name": "Python - Basketball players", "tags": [], "metadata": {"description": "
Find the number of people with heights greater then mean plus two times the standard deviation.
", "licence": "Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International"}, "statement": "A basketball talent scout is looking for tall people to be new players, analyse the data in the file linked below to find the potential candidates.
\nHow many people on the list are taller than the mean height plus two standard deviations?
\nThere are {n} people in the list.
\n{download_link(\"student_heights.csv\",csv)}
\nWARNING The data supplied for this question changes each time. If you retry this question you will need to redownload the csv.
\ncsv file in the same folder as your Python script. You'll need to use the pandas package. pd.readcsv could be useful - remember to deal with the pesky missing header and have your data somewhere your notebook can see it. You can apply functions to columns like df['height'].mean(). Also don'f forget we can apply logic to columns too: df[df['a'] < 100] gives all the items where column `a` has a value less than 100Import the pandas and then read in the csv.
{code_block(\"import pandas as pd\\ndf = pd.read_csv('student_heights.csv', header=None, names=['name','height'])\\ndf.head()\",\"python\")}
\nFind the mean and the standard deviation
\n{code_block(\"mean = df['height'].mean()\\nsd = df['height'].std()\",\"python\")}
\nfilter on two standard deviations above the mean and count
\n{code_block(\"df[df['height'] > mean + 2 * sd].count()\",\"python\")}
", "rulesets": {}, "extensions": ["download-text-file", "programming", "random_person", "stats"], "builtin_constants": {"e": true, "pi,\u03c0": true, "i": true, "j": false}, "constants": [], "variables": {"people": {"name": "people", "group": "Ungrouped variables", "definition": "map([x['name'],trunc(normalsample(mu, sigma))],x,random_people(n))", "description": "", "templateType": "anything", "can_override": false}, "n": {"name": "n", "group": "Ungrouped variables", "definition": "random(800..1010)", "description": "", "templateType": "anything", "can_override": false}, "mu": {"name": "mu", "group": "Ungrouped variables", "definition": "random(160..180)", "description": "", "templateType": "anything", "can_override": false}, "sigma": {"name": "sigma", "group": "Ungrouped variables", "definition": "random(5..15)", "description": "", "templateType": "anything", "can_override": false}, "ans": {"name": "ans", "group": "Ungrouped variables", "definition": "sum(map(if(x[1] > (mu+2*sigma),1,0),x,people))", "description": "This is the answer not based on the sample data - ignore this one
", "templateType": "anything", "can_override": false}, "csv": {"name": "csv", "group": "Ungrouped variables", "definition": "csv(people)", "description": "", "templateType": "anything", "can_override": false}, "x_bar": {"name": "x_bar", "group": "Ungrouped variables", "definition": "mean(map(x[1],x,people))", "description": "", "templateType": "anything", "can_override": false}, "sd": {"name": "sd", "group": "Ungrouped variables", "definition": "stdev(map(x[1],x,people),true)", "description": "", "templateType": "anything", "can_override": false}, "ans_2": {"name": "ans_2", "group": "Ungrouped variables", "definition": "sum(map(if(x[1] > (x_bar+2*sd),1,0),x,people))", "description": "", "templateType": "anything", "can_override": false}}, "variablesTest": {"condition": "", "maxRuns": 100}, "ungrouped_variables": ["people", "n", "mu", "sigma", "csv", "x_bar", "sd", "ans_2", "ans"], "variable_groups": [], "functions": {}, "preamble": {"js": "var x_ed = Numbas.extensions.programming.run_code(\"pyodide\", [\"print('hello')\"])", "css": ""}, "parts": [{"type": "numberentry", "useCustomName": false, "customName": "", "marks": 1, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "minValue": "{ans_2}", "maxValue": "{ans_2}", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "displayAnswer": "", "showFractionHint": true, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}], "partsMode": "all", "maxMarks": 0, "objectives": [], "penalties": [], "objectiveVisibility": "always", "penaltyVisibility": "always", "contributors": [{"name": "Ed Southwood", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/2415/"}, {"name": "Ben McGovern", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/4872/"}], "resources": []}]}], "contributors": [{"name": "Ed Southwood", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/2415/"}, {"name": "Ben McGovern", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/4872/"}]}