{ "cells": [ { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ ], "source": [ "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
IDNameSexAgeHeightWeightTeamNOCGamesYearSeasonCitySportEventMedal
01A DijiangM24.0180.080.0ChinaCHN1992 Summer1992SummerBarcelonaBasketballBasketball Men's BasketballNaN
12A LamusiM23.0170.060.0ChinaCHN2012 Summer2012SummerLondonJudoJudo Men's Extra-LightweightNaN
23Gunnar Nielsen AabyM24.0NaNNaNDenmarkDEN1920 Summer1920SummerAntwerpenFootballFootball Men's FootballNaN
34Edgar Lindenau AabyeM34.0NaNNaNDenmark/SwedenDEN1900 Summer1900SummerParisTug-Of-WarTug-Of-War Men's Tug-Of-WarGold
45Christine Jacoba AaftinkF21.0185.082.0NetherlandsNED1988 Winter1988WinterCalgarySpeed SkatingSpeed Skating Women's 500 metresNaN
\n", "
" ] }, "execution_count": 4, "metadata": { }, "output_type": "execute_result" } ], "source": [ "data = pd.read_csv('athlete_events.csv')\n", "data.head()" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false }, "source": [ "__1. How old were the youngest male and female participants of the 1996 Olympics?__\n", "\n", "- 16 and 15\n", "- 14 and 12 \n", "- 16 and 12\n", "- 13 and 11" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "(14.0, 12.0)" ] }, "execution_count": 5, "metadata": { }, "output_type": "execute_result" } ], "source": [ "data[(data['Sex'] == 'M') & (data['Games'] == '1996 Summer')]['Age'].min(), data[(data['Sex'] == 'F') & (data['Games'] == '1996 Summer')]['Age'].min()" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false }, "source": [ "__2. What was the percentage of male gymnasts among all the male participants of the 2000 Olympics? Consider only Gymnastics as a target sport. Round the answer to the first decimal.__\n", "\n", "Hint: here and further if needed drop duplicated sportsmen to count only unique ones.\n", "\n", "- 0.2\n", "- 1.5\n", "- 2.5\n", "- 7.7" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "1.5" ] }, "execution_count": 14, "metadata": { }, "output_type": "execute_result" } ], "source": [ "round(float(data[(data['Sport']=='Gymnastics') & (data['Sex'] == 'M') & (data['Games'] == '2000 Summer')]['Name'].nunique())/\n", " float(data[(data['Sex'] == 'M') & (data['Games'] == '2000 Summer')]['Name'].nunique())*100, 1)" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false }, "source": [ "\n", "__3. What are the mean and standard deviation of height for female basketball players participated in the 2000 Olympics? Round the answer to the first decimal.__\n", "\n", "- 178.5 and 7.2\n", "- 179.4 and 10\n", "- 180.7 and 6.7\n", "- 182.4 and 9.1" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "count 142.000000\n", "mean 182.387324\n", "std 9.139462\n", "min 162.000000\n", "25% 175.000000\n", "50% 182.000000\n", "75% 190.000000\n", "max 213.000000\n", "Name: Height, dtype: float64" ] }, "execution_count": 17, "metadata": { }, "output_type": "execute_result" } ], "source": [ "data[(data['Sex']=='F') & (data['Sport']=='Basketball') & (data['Games'] == '2000 Summer')]['Height'].describe()" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false }, "source": [ "__4. Find a sportsperson participated in the 2002 Olympics, with the highest weight among other participants of the same Olympics. What sport did he or she do?__\n", "\n", "- Judo\n", "- Bobsleigh\n", "- Weightlifting\n", "- Boxing" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "count 4062.000000\n", "mean 71.197070\n", "std 13.257178\n", "min 42.000000\n", "25% 61.000000\n", "50% 69.000000\n", "75% 80.000000\n", "max 123.000000\n", "Name: Weight, dtype: float64" ] }, "execution_count": 18, "metadata": { }, "output_type": "execute_result" } ], "source": [ "data[data['Games'] == '2002 Winter']['Weight'].describe()" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
IDNameSexAgeHeightWeightTeamNOCGamesYearSeasonCitySportEventMedal
9915450171Emmanuel HostacheM26.0190.0123.0FranceFRA2002 Winter2002WinterSalt Lake CityBobsleighBobsleigh Men's TwoNaN
\n", "
" ] }, "execution_count": 20, "metadata": { }, "output_type": "execute_result" } ], "source": [ "data[(data['Games'] == '2002 Winter') & (data['Weight'] == 123)]" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false }, "source": [ "__5. How many times did Pawe Abratkiewicz participate in the Olympics held in different years?__\n", "\n", "- 0\n", "- 1\n", "- 2\n", "- 3" ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "3" ] }, "execution_count": 23, "metadata": { }, "output_type": "execute_result" } ], "source": [ "data[data['Name'] == 'Pawe Abratkiewicz']['Games'].nunique()" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false }, "source": [ "__6. How many silver medals in tennis did sportspeople from the Australia team win at the 2000 Olympics? Count every medal from every sportsperson.__\n", "\n", "- 0\n", "- 1\n", "- 2\n", "- 3" ] }, { "cell_type": "code", "execution_count": 33, "metadata": { "collapsed": false, "scrolled": true }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
IDNameSexAgeHeightWeightTeamNOCGamesYearSeasonCitySportEventMedal
262820131504Todd Andrew WoodbridgeM29.0178.075.0AustraliaAUS2000 Summer2000SummerSydneyTennisTennis Men's DoublesSilver
262831131511Mark Raymond WoodfordeM34.0183.080.0AustraliaAUS2000 Summer2000SummerSydneyTennisTennis Men's DoublesSilver
\n", "
" ] }, "execution_count": 33, "metadata": { }, "output_type": "execute_result" } ], "source": [ "data[(data['Sport']=='Tennis') & (data['Games'] == '2000 Summer') & (data['Medal'] =='Silver') & (data['Team'] == 'Australia')]" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false }, "source": [ "__7. Is it true that Switzerland won fewer medals than Serbia at the 2016 Olympics? Do not consider NaN values in Medal column.__\n", "\n", "- Yes\n", "- No" ] }, { "cell_type": "code", "execution_count": 36, "metadata": { "collapsed": false, "scrolled": true }, "outputs": [ ], "source": [ "ds = data[(data['Team'].isin(['Serbia', 'Switzerland'])) & (data['Games'] =='2016 Summer') & (data['Medal'].isin(['Gold', 'Silver', 'Bronze']))]" ] }, { "cell_type": "code", "execution_count": 39, "metadata": { "collapsed": false, "scrolled": true }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "WARNING: Some output was deleted.\n" ] } ], "source": [ "ds" ] }, { "cell_type": "code", "execution_count": 38, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
countuniquetopfreq
Team
Serbia543Silver27
Switzerland113Gold6
\n", "
" ] }, "execution_count": 38, "metadata": { }, "output_type": "execute_result" } ], "source": [ "ds.groupby('Team')['Medal'].describe()" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false }, "source": [ "__8. What age category did the fewest and the most participants of the 2014 Olympics belong to?__\n", "\n", "- [45-55] and [25-35) correspondingly\n", "- [45-55] and [15-25) correspondingly\n", "- [35-45] and [25-35) correspondingly\n", "- [45-55] and [35-45) correspondingly" ] }, { "cell_type": "code", "execution_count": 49, "metadata": { "collapsed": false, "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "(5, 266)" ] }, "execution_count": 49, "metadata": { }, "output_type": "execute_result" } ], "source": [ "data[(data['Year']==2014) & (data['Age']>=45) & (data['Age']<=55)]['Name'].nunique(), data[(data['Year']==2014) & (data['Age']>=35) & (data['Age']<=45)]['Name'].nunique()" ] }, { "cell_type": "code", "execution_count": 50, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "(1397, 1193, 150)" ] }, "execution_count": 50, "metadata": { }, "output_type": "execute_result" } ], "source": [ "data[(data['Year']==2014) & (data['Age']>=25) & (data['Age']<35)]['Name'].nunique(), data[(data['Year']==2014) & (data['Age']>=15) & (data['Age']<25)]['Name'].nunique(), data[(data['Year']==2014) & (data['Age']>=35) & (data['Age']<45)]['Name'].nunique()" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false }, "source": [ "__9. Is it true that there were Summer Olympics held in Lake Placid? Is it true that there were Winter Olympics held in Sankt Moritz?__\n", "\n", "- Yes, Yes\n", "- Yes, No\n", "- No, Yes\n", "- No, No" ] }, { "cell_type": "code", "execution_count": 56, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
IDAgeHeightWeightYear
count0.00.00.00.00.0
meanNaNNaNNaNNaNNaN
stdNaNNaNNaNNaNNaN
minNaNNaNNaNNaNNaN
25%NaNNaNNaNNaNNaN
50%NaNNaNNaNNaNNaN
75%NaNNaNNaNNaNNaN
maxNaNNaNNaNNaNNaN
\n", "
" ] }, "execution_count": 56, "metadata": { }, "output_type": "execute_result" } ], "source": [ "data[(data['Season'] == 'Summer') & (data['City'].str.startswith('Lake Placid'))].describe()" ] }, { "cell_type": "code", "execution_count": 57, "metadata": { "collapsed": false, "scrolled": true }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
IDAgeHeightWeightYear
count1657.0000001563.000000238.000000159.0000001657.000000
mean65513.74894426.346769173.15546269.4716981940.975256
std37235.9014805.8271117.4994378.5867229.550020
min529.00000015.000000155.00000045.0000001928.000000
25%32961.00000022.000000168.00000065.0000001928.000000
50%63990.00000026.000000173.00000071.0000001948.000000
75%97263.00000029.000000178.00000074.0000001948.000000
max135466.00000054.000000211.000000103.0000001948.000000
\n", "
" ] }, "execution_count": 57, "metadata": { }, "output_type": "execute_result" } ], "source": [ "data[(data['Season'] == 'Winter') & (data['City'].str.startswith('Sankt Moritz'))].describe()" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false }, "source": [ "__10. What is the absolute difference between the number of unique sports at the 1996 Olympics and 2016 Olympics?__\n", "\n", "- 3\n", "- 10\n", "- 27\n", "- 34" ] }, { "cell_type": "code", "execution_count": 60, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "(31, 34)" ] }, "execution_count": 60, "metadata": { }, "output_type": "execute_result" } ], "source": [ "data[(data['Year'] == 1996)]['Sport'].nunique(), data[(data['Year'] == 2016)]['Sport'].nunique()" ] }, { "cell_type": "code", "execution_count": 0, "metadata": { "collapsed": false }, "outputs": [ ], "source": [ ] } ], "metadata": { "kernelspec": { "display_name": "SageMath (stable)", "language": "sagemath", "name": "sagemath" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.15" } }, "nbformat": 4, "nbformat_minor": 0 }