From 93509e3f7eb99001ce51718e1809643405b2dc50 Mon Sep 17 00:00:00 2001 From: nbgitpuller Date: Wed, 3 Jun 2020 21:33:12 +0000 Subject: [PATCH 1/6] Automatic commit by nbgitpuller --- .../Basic control structures.ipynb | 105 +- .../Dealing with Data - pandas.ipynb | 4151 ++++++++++++++++- 2 files changed, 4166 insertions(+), 90 deletions(-) diff --git a/002-basic-control-structures/Basic control structures.ipynb b/002-basic-control-structures/Basic control structures.ipynb index 906290a..9877b56 100644 --- a/002-basic-control-structures/Basic control structures.ipynb +++ b/002-basic-control-structures/Basic control structures.ipynb @@ -664,31 +664,17 @@ } }, "source": [ - "We can use negative numbers to count back from the end instead..." + "A slightly more niche extension of slicing is to set a step - in case we want to leapfrog our way from the start to the end:" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": { "slideshow": { - "slide_type": "notes" + "slide_type": "slide" } }, - "source": [ - "Which is \"start two from the end, and give me everything from there onwards\"" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "A slightly more niche extension of slicing is to set a step - in case we want to leapfrog our way from the start to the end:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, "outputs": [], "source": [ "things_to_do[::2]" @@ -697,7 +683,11 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "slideshow": { + "slide_type": "fragment" + } + }, "outputs": [], "source": [ "things_to_do[1::2]" @@ -713,12 +703,38 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "slideshow": { + "slide_type": "fragment" + } + }, "outputs": [], "source": [ "things_to_do[::-1]" ] }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "notes" + } + }, + "source": [ + "We can use negative numbers to count back from the end instead..." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "notes" + } + }, + "source": [ + "Which is \"start two from the end, and give me everything from there onwards\"" + ] + }, { "cell_type": "markdown", "metadata": { @@ -818,25 +834,25 @@ ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": { - "slideshow": { - "slide_type": "notes" - } + "scrolled": true }, + "outputs": [], "source": [ - "...but not..." + "my_meetup_dot_com_profile[2]" ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": { - "scrolled": true + "slideshow": { + "slide_type": "notes" + } }, - "outputs": [], "source": [ - "my_meetup_dot_com_profile[2]" + "...but not..." ] }, { @@ -1344,17 +1360,6 @@ "# Exercise" ] }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "notes" - } - }, - "source": [ - "...if we have time..." - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -1405,7 +1410,11 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, "source": [ "### Exercise: Zipping Up\n", "\n", @@ -1415,13 +1424,21 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "slideshow": { + "slide_type": "notes" + } + }, "outputs": [], "source": [] }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "slideshow": { + "slide_type": "fragment" + } + }, "source": [ "A handy function Python provides is `zip` - it lets you take multiple iterables, and pair them together in sequence:" ] diff --git a/009-data-analysis/Dealing with Data - pandas.ipynb b/009-data-analysis/Dealing with Data - pandas.ipynb index 80b6895..058d611 100644 --- a/009-data-analysis/Dealing with Data - pandas.ipynb +++ b/009-data-analysis/Dealing with Data - pandas.ipynb @@ -159,13 +159,299 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": { "slideshow": { "slide_type": "notes" } }, - "outputs": [], + "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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Table 1Unnamed: 1Unnamed: 2Unnamed: 3Unnamed: 4Unnamed: 5Unnamed: 7
4NaN1971.01981.0000001991.0000002001.0000002009.0000002009
5Food and non-alcoholic beverages100.0104.640913117.230576136.729755151.00898883.813
6Alcoholic beverages and tobacco100.099.23749792.06420488.02422189.61330231.128
7Clothing and footwear100.0119.877158186.847400344.276183552.54686047.599
8Housing, water and fuels2100.0116.734336138.879523152.250032160.082001193.447
9Furnishings, household equipment and maintenance100.0116.808722159.656426261.638586262.68252443.867
10Miscellaneous goods and services100.0120.876377240.394746336.047068377.225149104.765
12Restaurants and hotels3100.0125.594386167.157564193.105120185.49466888.763
13Recreation and culture100.0158.242026279.165652544.963883868.80935099.26
14Transport100.0127.948926180.949507246.488683272.763784124.616
15Communication100.0190.027855306.406685789.5821731126.12813418.747
16Health100.0124.598291182.273504187.760684229.26495714.283
17Education100.0160.173877199.316912254.936866221.87952813.024
18NaNNaNNaNNaNNaNNaN
19Total domestic household expenditure100.0120.735811166.460085225.223993259.495168863.312
20Total goods100.0116.882766155.755787226.782179285.454027411.727
21Total services100.0127.667167183.960495230.874717244.720566451.585
23UK tourist expenditure abroad100.0193.380615298.082480699.054374576.33307128.994
24less foreign tourist expenditure100.0151.616612187.182066222.215836257.81003019.554
26Household final consumption expenditure4100.0121.341138168.287800232.291680264.930072872.752
\n", + "
" + ], + "text/plain": [ + " Table 1 Unnamed: 1 Unnamed: 2 \\\n", + "4 NaN 1971.0 1981.000000 \n", + "5 Food and non-alcoholic beverages 100.0 104.640913 \n", + "6 Alcoholic beverages and tobacco 100.0 99.237497 \n", + "7 Clothing and footwear 100.0 119.877158 \n", + "8 Housing, water and fuels2 100.0 116.734336 \n", + "9 Furnishings, household equipment and maintenance 100.0 116.808722 \n", + "10 Miscellaneous goods and services 100.0 120.876377 \n", + "12 Restaurants and hotels3 100.0 125.594386 \n", + "13 Recreation and culture 100.0 158.242026 \n", + "14 Transport 100.0 127.948926 \n", + "15 Communication 100.0 190.027855 \n", + "16 Health 100.0 124.598291 \n", + "17 Education 100.0 160.173877 \n", + "18 NaN NaN \n", + "19 Total domestic household expenditure 100.0 120.735811 \n", + "20 Total goods 100.0 116.882766 \n", + "21 Total services 100.0 127.667167 \n", + "23 UK tourist expenditure abroad 100.0 193.380615 \n", + "24 less foreign tourist expenditure 100.0 151.616612 \n", + "26 Household final consumption expenditure4 100.0 121.341138 \n", + "\n", + " Unnamed: 3 Unnamed: 4 Unnamed: 5 Unnamed: 7 \n", + "4 1991.000000 2001.000000 2009.000000 2009 \n", + "5 117.230576 136.729755 151.008988 83.813 \n", + "6 92.064204 88.024221 89.613302 31.128 \n", + "7 186.847400 344.276183 552.546860 47.599 \n", + "8 138.879523 152.250032 160.082001 193.447 \n", + "9 159.656426 261.638586 262.682524 43.867 \n", + "10 240.394746 336.047068 377.225149 104.765 \n", + "12 167.157564 193.105120 185.494668 88.763 \n", + "13 279.165652 544.963883 868.809350 99.26 \n", + "14 180.949507 246.488683 272.763784 124.616 \n", + "15 306.406685 789.582173 1126.128134 18.747 \n", + "16 182.273504 187.760684 229.264957 14.283 \n", + "17 199.316912 254.936866 221.879528 13.024 \n", + "18 NaN NaN NaN NaN \n", + "19 166.460085 225.223993 259.495168 863.312 \n", + "20 155.755787 226.782179 285.454027 411.727 \n", + "21 183.960495 230.874717 244.720566 451.585 \n", + "23 298.082480 699.054374 576.333071 28.994 \n", + "24 187.182066 222.215836 257.810030 19.554 \n", + "26 168.287800 232.291680 264.930072 872.752 " + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "import pandas as pd\n", "\n", @@ -179,8 +465,8 @@ "df = df.loc[4:26]\n", "\n", "# [D] Challenge here!\n", - "#df = df.******(how='***', axis=0)\n", - "#df = df.******(how='***', axis=1)\n", + "df = df.dropna(how='all', axis=0)\n", + "df = df.dropna(how='all', axis=1)\n", "df" ] }, @@ -193,13 +479,37 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": { "slideshow": { "slide_type": "slide" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "['Expenditure',\n", + " 'Figure 1',\n", + " 'Table 1',\n", + " 'Figure 2',\n", + " 'Figure 3',\n", + " 'Figure 4',\n", + " 'Figure 5',\n", + " 'Figure 6',\n", + " 'Figure 7',\n", + " 'Figure 8',\n", + " 'Figure 9',\n", + " 'Figure 10',\n", + " 'Figure 11',\n", + " 'Figure 12']" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "excel_file.sheet_names" ] @@ -285,14 +595,360 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": { "scrolled": true, "slideshow": { "slide_type": "slide" } }, - "outputs": [], + "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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Table 1Unnamed: 1Unnamed: 2Unnamed: 3Unnamed: 4Unnamed: 5Unnamed: 6Unnamed: 7
4NaN1971.01981.0000001991.0000002001.0000002009.000000NaN2009
5Food and non-alcoholic beverages100.0104.640913117.230576136.729755151.008988NaN83.813
6Alcoholic beverages and tobacco100.099.23749792.06420488.02422189.613302NaN31.128
7Clothing and footwear100.0119.877158186.847400344.276183552.546860NaN47.599
8Housing, water and fuels2100.0116.734336138.879523152.250032160.082001NaN193.447
9Furnishings, household equipment and maintenance100.0116.808722159.656426261.638586262.682524NaN43.867
10Miscellaneous goods and services100.0120.876377240.394746336.047068377.225149NaN104.765
11NaNNaNNaNNaNNaNNaNNaNNaN
12Restaurants and hotels3100.0125.594386167.157564193.105120185.494668NaN88.763
13Recreation and culture100.0158.242026279.165652544.963883868.809350NaN99.26
14Transport100.0127.948926180.949507246.488683272.763784NaN124.616
15Communication100.0190.027855306.406685789.5821731126.128134NaN18.747
16Health100.0124.598291182.273504187.760684229.264957NaN14.283
17Education100.0160.173877199.316912254.936866221.879528NaN13.024
18NaNNaNNaNNaNNaNNaNNaN
19Total domestic household expenditure100.0120.735811166.460085225.223993259.495168NaN863.312
20Total goods100.0116.882766155.755787226.782179285.454027NaN411.727
21Total services100.0127.667167183.960495230.874717244.720566NaN451.585
22NaNNaNNaNNaNNaNNaNNaNNaN
23UK tourist expenditure abroad100.0193.380615298.082480699.054374576.333071NaN28.994
24less foreign tourist expenditure100.0151.616612187.182066222.215836257.810030NaN19.554
25NaNNaNNaNNaNNaNNaNNaNNaN
26Household final consumption expenditure4100.0121.341138168.287800232.291680264.930072NaN872.752
\n", + "
" + ], + "text/plain": [ + " Table 1 Unnamed: 1 Unnamed: 2 \\\n", + "4 NaN 1971.0 1981.000000 \n", + "5 Food and non-alcoholic beverages 100.0 104.640913 \n", + "6 Alcoholic beverages and tobacco 100.0 99.237497 \n", + "7 Clothing and footwear 100.0 119.877158 \n", + "8 Housing, water and fuels2 100.0 116.734336 \n", + "9 Furnishings, household equipment and maintenance 100.0 116.808722 \n", + "10 Miscellaneous goods and services 100.0 120.876377 \n", + "11 NaN NaN NaN \n", + "12 Restaurants and hotels3 100.0 125.594386 \n", + "13 Recreation and culture 100.0 158.242026 \n", + "14 Transport 100.0 127.948926 \n", + "15 Communication 100.0 190.027855 \n", + "16 Health 100.0 124.598291 \n", + "17 Education 100.0 160.173877 \n", + "18 NaN NaN \n", + "19 Total domestic household expenditure 100.0 120.735811 \n", + "20 Total goods 100.0 116.882766 \n", + "21 Total services 100.0 127.667167 \n", + "22 NaN NaN NaN \n", + "23 UK tourist expenditure abroad 100.0 193.380615 \n", + "24 less foreign tourist expenditure 100.0 151.616612 \n", + "25 NaN NaN NaN \n", + "26 Household final consumption expenditure4 100.0 121.341138 \n", + "\n", + " Unnamed: 3 Unnamed: 4 Unnamed: 5 Unnamed: 6 Unnamed: 7 \n", + "4 1991.000000 2001.000000 2009.000000 NaN 2009 \n", + "5 117.230576 136.729755 151.008988 NaN 83.813 \n", + "6 92.064204 88.024221 89.613302 NaN 31.128 \n", + "7 186.847400 344.276183 552.546860 NaN 47.599 \n", + "8 138.879523 152.250032 160.082001 NaN 193.447 \n", + "9 159.656426 261.638586 262.682524 NaN 43.867 \n", + "10 240.394746 336.047068 377.225149 NaN 104.765 \n", + "11 NaN NaN NaN NaN NaN \n", + "12 167.157564 193.105120 185.494668 NaN 88.763 \n", + "13 279.165652 544.963883 868.809350 NaN 99.26 \n", + "14 180.949507 246.488683 272.763784 NaN 124.616 \n", + "15 306.406685 789.582173 1126.128134 NaN 18.747 \n", + "16 182.273504 187.760684 229.264957 NaN 14.283 \n", + "17 199.316912 254.936866 221.879528 NaN 13.024 \n", + "18 NaN NaN NaN NaN NaN \n", + "19 166.460085 225.223993 259.495168 NaN 863.312 \n", + "20 155.755787 226.782179 285.454027 NaN 411.727 \n", + "21 183.960495 230.874717 244.720566 NaN 451.585 \n", + "22 NaN NaN NaN NaN NaN \n", + "23 298.082480 699.054374 576.333071 NaN 28.994 \n", + "24 187.182066 222.215836 257.810030 NaN 19.554 \n", + "25 NaN NaN NaN NaN NaN \n", + "26 168.287800 232.291680 264.930072 NaN 872.752 " + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "df" ] @@ -332,13 +988,32 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": { "slideshow": { "slide_type": "-" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "Table 1 Alcoholic beverages and tobacco\n", + "Unnamed: 1 100\n", + "Unnamed: 2 99.2375\n", + "Unnamed: 3 92.0642\n", + "Unnamed: 4 88.0242\n", + "Unnamed: 5 89.6133\n", + "Unnamed: 6 NaN\n", + "Unnamed: 7 31.128\n", + "Name: 6, dtype: object" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "df.loc[6]" ] @@ -352,9 +1027,121 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, - "outputs": [], + "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", + "
ABCDEFGH
4NaN1971.01981.0000001991.0000002001.0000002009.000000NaN2009
5Food and non-alcoholic beverages100.0104.640913117.230576136.729755151.008988NaN83.813
6Alcoholic beverages and tobacco100.099.23749792.06420488.02422189.613302NaN31.128
7Clothing and footwear100.0119.877158186.847400344.276183552.546860NaN47.599
8Housing, water and fuels2100.0116.734336138.879523152.250032160.082001NaN193.447
\n", + "
" + ], + "text/plain": [ + " A B C D \\\n", + "4 NaN 1971.0 1981.000000 1991.000000 \n", + "5 Food and non-alcoholic beverages 100.0 104.640913 117.230576 \n", + "6 Alcoholic beverages and tobacco 100.0 99.237497 92.064204 \n", + "7 Clothing and footwear 100.0 119.877158 186.847400 \n", + "8 Housing, water and fuels2 100.0 116.734336 138.879523 \n", + "\n", + " E F G H \n", + "4 2001.000000 2009.000000 NaN 2009 \n", + "5 136.729755 151.008988 NaN 83.813 \n", + "6 88.024221 89.613302 NaN 31.128 \n", + "7 344.276183 552.546860 NaN 47.599 \n", + "8 152.250032 160.082001 NaN 193.447 " + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "import string\n", "column_count = len(df.columns)\n", @@ -377,14 +1164,87 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": { "scrolled": true, "slideshow": { "slide_type": "notes" } }, - "outputs": [], + "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", + "
ABCDEFGH
6Alcoholic beverages and tobacco100.099.23749792.06420488.02422189.613302NaN31.128
7Clothing and footwear100.0119.877158186.847400344.276183552.546860NaN47.599
\n", + "
" + ], + "text/plain": [ + " A B C D E \\\n", + "6 Alcoholic beverages and tobacco 100.0 99.237497 92.064204 88.024221 \n", + "7 Clothing and footwear 100.0 119.877158 186.847400 344.276183 \n", + "\n", + " F G H \n", + "6 89.613302 NaN 31.128 \n", + "7 552.546860 NaN 47.599 " + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "df.loc[6:7]" ] @@ -425,13 +1285,32 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": { "slideshow": { "slide_type": "fragment" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "A NaN\n", + "B 1971\n", + "C 1981\n", + "D 1991\n", + "E 2001\n", + "F 2009\n", + "G NaN\n", + "H 2009\n", + "Name: 4, dtype: object" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "df.loc[4]" ] @@ -449,7 +1328,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": { "slideshow": { "slide_type": "slide" @@ -460,6 +1339,361 @@ "df = df.loc[4:26]" ] }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
ABCDEFGH
4NaN1971.01981.0000001991.0000002001.0000002009.000000NaN2009
5Food and non-alcoholic beverages100.0104.640913117.230576136.729755151.008988NaN83.813
6Alcoholic beverages and tobacco100.099.23749792.06420488.02422189.613302NaN31.128
7Clothing and footwear100.0119.877158186.847400344.276183552.546860NaN47.599
8Housing, water and fuels2100.0116.734336138.879523152.250032160.082001NaN193.447
9Furnishings, household equipment and maintenance100.0116.808722159.656426261.638586262.682524NaN43.867
10Miscellaneous goods and services100.0120.876377240.394746336.047068377.225149NaN104.765
11NaNNaNNaNNaNNaNNaNNaNNaN
12Restaurants and hotels3100.0125.594386167.157564193.105120185.494668NaN88.763
13Recreation and culture100.0158.242026279.165652544.963883868.809350NaN99.26
14Transport100.0127.948926180.949507246.488683272.763784NaN124.616
15Communication100.0190.027855306.406685789.5821731126.128134NaN18.747
16Health100.0124.598291182.273504187.760684229.264957NaN14.283
17Education100.0160.173877199.316912254.936866221.879528NaN13.024
18NaNNaNNaNNaNNaNNaNNaN
19Total domestic household expenditure100.0120.735811166.460085225.223993259.495168NaN863.312
20Total goods100.0116.882766155.755787226.782179285.454027NaN411.727
21Total services100.0127.667167183.960495230.874717244.720566NaN451.585
22NaNNaNNaNNaNNaNNaNNaNNaN
23UK tourist expenditure abroad100.0193.380615298.082480699.054374576.333071NaN28.994
24less foreign tourist expenditure100.0151.616612187.182066222.215836257.810030NaN19.554
25NaNNaNNaNNaNNaNNaNNaNNaN
26Household final consumption expenditure4100.0121.341138168.287800232.291680264.930072NaN872.752
\n", + "
" + ], + "text/plain": [ + " A B C \\\n", + "4 NaN 1971.0 1981.000000 \n", + "5 Food and non-alcoholic beverages 100.0 104.640913 \n", + "6 Alcoholic beverages and tobacco 100.0 99.237497 \n", + "7 Clothing and footwear 100.0 119.877158 \n", + "8 Housing, water and fuels2 100.0 116.734336 \n", + "9 Furnishings, household equipment and maintenance 100.0 116.808722 \n", + "10 Miscellaneous goods and services 100.0 120.876377 \n", + "11 NaN NaN NaN \n", + "12 Restaurants and hotels3 100.0 125.594386 \n", + "13 Recreation and culture 100.0 158.242026 \n", + "14 Transport 100.0 127.948926 \n", + "15 Communication 100.0 190.027855 \n", + "16 Health 100.0 124.598291 \n", + "17 Education 100.0 160.173877 \n", + "18 NaN NaN \n", + "19 Total domestic household expenditure 100.0 120.735811 \n", + "20 Total goods 100.0 116.882766 \n", + "21 Total services 100.0 127.667167 \n", + "22 NaN NaN NaN \n", + "23 UK tourist expenditure abroad 100.0 193.380615 \n", + "24 less foreign tourist expenditure 100.0 151.616612 \n", + "25 NaN NaN NaN \n", + "26 Household final consumption expenditure4 100.0 121.341138 \n", + "\n", + " D E F G H \n", + "4 1991.000000 2001.000000 2009.000000 NaN 2009 \n", + "5 117.230576 136.729755 151.008988 NaN 83.813 \n", + "6 92.064204 88.024221 89.613302 NaN 31.128 \n", + "7 186.847400 344.276183 552.546860 NaN 47.599 \n", + "8 138.879523 152.250032 160.082001 NaN 193.447 \n", + "9 159.656426 261.638586 262.682524 NaN 43.867 \n", + "10 240.394746 336.047068 377.225149 NaN 104.765 \n", + "11 NaN NaN NaN NaN NaN \n", + "12 167.157564 193.105120 185.494668 NaN 88.763 \n", + "13 279.165652 544.963883 868.809350 NaN 99.26 \n", + "14 180.949507 246.488683 272.763784 NaN 124.616 \n", + "15 306.406685 789.582173 1126.128134 NaN 18.747 \n", + "16 182.273504 187.760684 229.264957 NaN 14.283 \n", + "17 199.316912 254.936866 221.879528 NaN 13.024 \n", + "18 NaN NaN NaN NaN NaN \n", + "19 166.460085 225.223993 259.495168 NaN 863.312 \n", + "20 155.755787 226.782179 285.454027 NaN 411.727 \n", + "21 183.960495 230.874717 244.720566 NaN 451.585 \n", + "22 NaN NaN NaN NaN NaN \n", + "23 298.082480 699.054374 576.333071 NaN 28.994 \n", + "24 187.182066 222.215836 257.810030 NaN 19.554 \n", + "25 NaN NaN NaN NaN NaN \n", + "26 168.287800 232.291680 264.930072 NaN 872.752 " + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df" + ] + }, { "cell_type": "markdown", "metadata": { @@ -473,9 +1707,66 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": {}, - "outputs": [], + "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", + "
BC
41971.01981.000000
5100.0104.640913
6100.099.237497
\n", + "
" + ], + "text/plain": [ + " B C\n", + "4 1971.0 1981.000000\n", + "5 100.0 104.640913\n", + "6 100.0 99.237497" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "df.loc[4:6, \"B\":\"C\"]" ] @@ -567,13 +1858,288 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 48, "metadata": { "slideshow": { "slide_type": "notes" } }, - "outputs": [], + "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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Years197119811991200120092009
Category
Food and non-alcoholic beverages100.0104.640913117.230576136.729755151.00898883.813
Alcoholic beverages and tobacco100.099.23749792.06420488.02422189.61330231.128
Clothing and footwear100.0119.877158186.847400344.276183552.54686047.599
Housing, water and fuels2100.0116.734336138.879523152.250032160.082001193.447
Furnishings, household equipment and maintenance100.0116.808722159.656426261.638586262.68252443.867
Miscellaneous goods and services100.0120.876377240.394746336.047068377.225149104.765
Restaurants and hotels3100.0125.594386167.157564193.105120185.49466888.763
Recreation and culture100.0158.242026279.165652544.963883868.80935099.26
Transport100.0127.948926180.949507246.488683272.763784124.616
Communication100.0190.027855306.406685789.5821731126.12813418.747
Health100.0124.598291182.273504187.760684229.26495714.283
Education100.0160.173877199.316912254.936866221.87952813.024
Total domestic household expenditure100.0120.735811166.460085225.223993259.495168863.312
Total goods100.0116.882766155.755787226.782179285.454027411.727
Total services100.0127.667167183.960495230.874717244.720566451.585
UK tourist expenditure abroad100.0193.380615298.082480699.054374576.33307128.994
less foreign tourist expenditure100.0151.616612187.182066222.215836257.81003019.554
Household final consumption expenditure4100.0121.341138168.287800232.291680264.930072872.752
\n", + "
" + ], + "text/plain": [ + "Years 1971 1981 \\\n", + "Category \n", + "Food and non-alcoholic beverages 100.0 104.640913 \n", + "Alcoholic beverages and tobacco 100.0 99.237497 \n", + "Clothing and footwear 100.0 119.877158 \n", + "Housing, water and fuels2 100.0 116.734336 \n", + "Furnishings, household equipment and maintenance 100.0 116.808722 \n", + "Miscellaneous goods and services 100.0 120.876377 \n", + "Restaurants and hotels3 100.0 125.594386 \n", + "Recreation and culture 100.0 158.242026 \n", + "Transport 100.0 127.948926 \n", + "Communication 100.0 190.027855 \n", + "Health 100.0 124.598291 \n", + "Education 100.0 160.173877 \n", + "Total domestic household expenditure 100.0 120.735811 \n", + " Total goods 100.0 116.882766 \n", + " Total services 100.0 127.667167 \n", + "UK tourist expenditure abroad 100.0 193.380615 \n", + " less foreign tourist expenditure 100.0 151.616612 \n", + "Household final consumption expenditure4 100.0 121.341138 \n", + "\n", + "Years 1991 2001 \\\n", + "Category \n", + "Food and non-alcoholic beverages 117.230576 136.729755 \n", + "Alcoholic beverages and tobacco 92.064204 88.024221 \n", + "Clothing and footwear 186.847400 344.276183 \n", + "Housing, water and fuels2 138.879523 152.250032 \n", + "Furnishings, household equipment and maintenance 159.656426 261.638586 \n", + "Miscellaneous goods and services 240.394746 336.047068 \n", + "Restaurants and hotels3 167.157564 193.105120 \n", + "Recreation and culture 279.165652 544.963883 \n", + "Transport 180.949507 246.488683 \n", + "Communication 306.406685 789.582173 \n", + "Health 182.273504 187.760684 \n", + "Education 199.316912 254.936866 \n", + "Total domestic household expenditure 166.460085 225.223993 \n", + " Total goods 155.755787 226.782179 \n", + " Total services 183.960495 230.874717 \n", + "UK tourist expenditure abroad 298.082480 699.054374 \n", + " less foreign tourist expenditure 187.182066 222.215836 \n", + "Household final consumption expenditure4 168.287800 232.291680 \n", + "\n", + "Years 2009 2009 \n", + "Category \n", + "Food and non-alcoholic beverages 151.008988 83.813 \n", + "Alcoholic beverages and tobacco 89.613302 31.128 \n", + "Clothing and footwear 552.546860 47.599 \n", + "Housing, water and fuels2 160.082001 193.447 \n", + "Furnishings, household equipment and maintenance 262.682524 43.867 \n", + "Miscellaneous goods and services 377.225149 104.765 \n", + "Restaurants and hotels3 185.494668 88.763 \n", + "Recreation and culture 868.809350 99.26 \n", + "Transport 272.763784 124.616 \n", + "Communication 1126.128134 18.747 \n", + "Health 229.264957 14.283 \n", + "Education 221.879528 13.024 \n", + "Total domestic household expenditure 259.495168 863.312 \n", + " Total goods 285.454027 411.727 \n", + " Total services 244.720566 451.585 \n", + "UK tourist expenditure abroad 576.333071 28.994 \n", + " less foreign tourist expenditure 257.810030 19.554 \n", + "Household final consumption expenditure4 264.930072 872.752 " + ] + }, + "execution_count": 48, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "## SECOND VERSION OF SCRIPT\n", "\n", @@ -595,11 +2161,12 @@ "# [E] Reindex/column to desired table\n", "df.loc[4, \"Table 1\"] = 0 # E1\n", "df.columns = df.loc[4, :].astype(int) # E2\n", - "df = df[1:] # E3\n", + "df = df.iloc[1:] # E3\n", "df.index = df[0] # E4\n", "df.index.name = \"Category\" # E5\n", - "df = df.loc[:, \"A\":] # E6\n", - "df.columns.name = \"Years\" # E7" + "df = df.loc[:, \"1971\":] # E6\n", + "df.columns.name = \"Years\" # E7\n", + "df" ] }, { @@ -619,13 +2186,288 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 49, "metadata": { "slideshow": { "slide_type": "slide" } }, - "outputs": [], + "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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Years197119811991200120092009.1
Category
Food and non-alcoholic beverages100.0104.640913117.230576136.729755151.00898883.813
Alcoholic beverages and tobacco100.099.23749792.06420488.02422189.61330231.128
Clothing and footwear100.0119.877158186.847400344.276183552.54686047.599
Housing, water and fuels2100.0116.734336138.879523152.250032160.082001193.447
Furnishings, household equipment and maintenance100.0116.808722159.656426261.638586262.68252443.867
Miscellaneous goods and services100.0120.876377240.394746336.047068377.225149104.765
Restaurants and hotels3100.0125.594386167.157564193.105120185.49466888.763
Recreation and culture100.0158.242026279.165652544.963883868.80935099.260
Transport100.0127.948926180.949507246.488683272.763784124.616
Communication100.0190.027855306.406685789.5821731126.12813418.747
Health100.0124.598291182.273504187.760684229.26495714.283
Education100.0160.173877199.316912254.936866221.87952813.024
Total domestic household expenditure100.0120.735811166.460085225.223993259.495168863.312
Total goods100.0116.882766155.755787226.782179285.454027411.727
Total services100.0127.667167183.960495230.874717244.720566451.585
UK tourist expenditure abroad100.0193.380615298.082480699.054374576.33307128.994
less foreign tourist expenditure100.0151.616612187.182066222.215836257.81003019.554
Household final consumption expenditure4100.0121.341138168.287800232.291680264.930072872.752
\n", + "
" + ], + "text/plain": [ + "Years 1971 1981 \\\n", + "Category \n", + "Food and non-alcoholic beverages 100.0 104.640913 \n", + "Alcoholic beverages and tobacco 100.0 99.237497 \n", + "Clothing and footwear 100.0 119.877158 \n", + "Housing, water and fuels2 100.0 116.734336 \n", + "Furnishings, household equipment and maintenance 100.0 116.808722 \n", + "Miscellaneous goods and services 100.0 120.876377 \n", + "Restaurants and hotels3 100.0 125.594386 \n", + "Recreation and culture 100.0 158.242026 \n", + "Transport 100.0 127.948926 \n", + "Communication 100.0 190.027855 \n", + "Health 100.0 124.598291 \n", + "Education 100.0 160.173877 \n", + "Total domestic household expenditure 100.0 120.735811 \n", + " Total goods 100.0 116.882766 \n", + " Total services 100.0 127.667167 \n", + "UK tourist expenditure abroad 100.0 193.380615 \n", + " less foreign tourist expenditure 100.0 151.616612 \n", + "Household final consumption expenditure4 100.0 121.341138 \n", + "\n", + "Years 1991 2001 \\\n", + "Category \n", + "Food and non-alcoholic beverages 117.230576 136.729755 \n", + "Alcoholic beverages and tobacco 92.064204 88.024221 \n", + "Clothing and footwear 186.847400 344.276183 \n", + "Housing, water and fuels2 138.879523 152.250032 \n", + "Furnishings, household equipment and maintenance 159.656426 261.638586 \n", + "Miscellaneous goods and services 240.394746 336.047068 \n", + "Restaurants and hotels3 167.157564 193.105120 \n", + "Recreation and culture 279.165652 544.963883 \n", + "Transport 180.949507 246.488683 \n", + "Communication 306.406685 789.582173 \n", + "Health 182.273504 187.760684 \n", + "Education 199.316912 254.936866 \n", + "Total domestic household expenditure 166.460085 225.223993 \n", + " Total goods 155.755787 226.782179 \n", + " Total services 183.960495 230.874717 \n", + "UK tourist expenditure abroad 298.082480 699.054374 \n", + " less foreign tourist expenditure 187.182066 222.215836 \n", + "Household final consumption expenditure4 168.287800 232.291680 \n", + "\n", + "Years 2009 2009.1 \n", + "Category \n", + "Food and non-alcoholic beverages 151.008988 83.813 \n", + "Alcoholic beverages and tobacco 89.613302 31.128 \n", + "Clothing and footwear 552.546860 47.599 \n", + "Housing, water and fuels2 160.082001 193.447 \n", + "Furnishings, household equipment and maintenance 262.682524 43.867 \n", + "Miscellaneous goods and services 377.225149 104.765 \n", + "Restaurants and hotels3 185.494668 88.763 \n", + "Recreation and culture 868.809350 99.260 \n", + "Transport 272.763784 124.616 \n", + "Communication 1126.128134 18.747 \n", + "Health 229.264957 14.283 \n", + "Education 221.879528 13.024 \n", + "Total domestic household expenditure 259.495168 863.312 \n", + " Total goods 285.454027 411.727 \n", + " Total services 244.720566 451.585 \n", + "UK tourist expenditure abroad 576.333071 28.994 \n", + " less foreign tourist expenditure 257.810030 19.554 \n", + "Household final consumption expenditure4 264.930072 872.752 " + ] + }, + "execution_count": 49, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "## THIRD VERSION OF SCRIPT\n", "\n", @@ -676,13 +2518,94 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 65, "metadata": { "slideshow": { "slide_type": "notes" } }, - "outputs": [], + "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", + "
%1971today's money
1971100.0000001.664731
1981190.0278553.163452
1991306.4066855.100846
2001789.58217313.144416
20091126.12813418.747000
\n", + "
" + ], + "text/plain": [ + " %1971 today's money\n", + "1971 100.000000 1.664731\n", + "1981 190.027855 3.163452\n", + "1991 306.406685 5.100846\n", + "2001 789.582173 13.144416\n", + "2009 1126.128134 18.747000" + ] + }, + "execution_count": 65, + "metadata": {}, + "output_type": "execute_result" + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAEICAYAAACzliQjAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAaB0lEQVR4nO3df3RV5Z3v8fc3CYpWqvySokFBm2uBxFAIiNoC4ih0oYLlagF/gIh4UTqW2zLiMGvGahmx9VbbVbEXFbW93gBaKKgzWn6o2NZqoobhV1mAMhJgTKCoiD8TvvPH2SSHkCA5J5ydw/N5reU6Zz/72Wd/8wQ/Z+c5++xt7o6IiIQhJ+4CREQkcxT6IiIBUeiLiAREoS8iEhCFvohIQBT6IiIByYu7gC/TqVMn7969e9xliIhklTfeeGOXu3du2N7qQ7979+6Ul5fHXYaISFYxs/9srF3TOyIiAVHoi4gERKEvIhKQVj+n35gvvviCyspKPv3007hLkSPQtm1b8vPzadOmTdyliAQvK0O/srKSdu3a0b17d8ws7nLkMNyd3bt3U1lZSY8ePeIuRyR4WTm98+mnn9KxY0cFfhYwMzp27Ki/ykRaiawMfUCBn0X0uxJpPbI29ONUXV3Nt771LQoLC/n9739f1z5y5Eh27NgBwFNPPUXv3r3Jyck56HsGn3/+OTfccANFRUUUFxfz0ksvAbB371769OlT91+nTp34wQ9+AMCqVavo27cveXl5PP3005n7QUXkmJOVc/oNdZ/xXIu+3tbZIw67vrS0lPHjxzNmzBiGDx/OqFGjeOaZZ+jbty+nnXYaAIWFhSxatIibb775oG0ffvhhANasWUNVVRXf+c53KCsro127dlRUVNT169evH9/97ncBOOOMM3j88ce57777WvLHFJEGWiJLviw/4nZMhH6mtWnThk8++YTPPvuMnJwcampqeOCBB3jmmWfq+vTs2bPRbdevX8/FF18MwKmnnsopp5xCeXk5AwYMqOuzadMmqqqq+Pa3vw0kvpUMkJOjP8xEJD1KkRSMGzeOF154geHDh3PnnXcyZ84crr/+ek488cQv3ba4uJglS5ZQU1PDO++8wxtvvMG2bdsO6lNaWsr3vvc9zYWLSIvTkX4KTj75ZJ57LvFn4J49e7j33ntZtGgRN910E3v27OGHP/wh559/fqPbTpw4kQ0bNlBSUsKZZ57JBRdcQF7ewb+G+fPn89vf/vao/xwiEh6FfpruuusuZs6cSWlpKf369WPcuHGMHDmSF198sdH+eXl53H///XXLF1xwAQUFBXXLq1evpqamhn79+h312kUkPJreScOmTZvYsWMHgwcP5uOPPyYnJwczO+w56R9//DH79u0DYNmyZeTl5dGrV6+69aWlpYwdO/ao1y4iYVLop2HmzJn85Cc/AWDs2LE8/vjjDBw4kB/96EcsXryY/Px8Xn31VUaMGMGwYcMAqKqqom/fvvTs2ZN77733kGmchQsXHhL6ZWVl5Ofn89RTT3HzzTfTu3fvzPyAInLMMXePu4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QPxlRWLeUCZmc0HDvyF043E/yePxlZVPLJuLDS904CZveXu32yk3YBB7v5yDGXFwsweB44DvgJ8TGIe+3lgKNDO3a+Or7rMMrN5JD6kWwGMBLa7+/82sxOBN939G7EWmGFm1gu4gsSHl0biaHdpiNOh2TYWCv0GzGycuwd1Cl5Tom8YXkUi7J4GziMx7fUu8KC774uxvIwyszbATSSmu1aTuOtbrZmdAJzq7v8Za4EiR0ihLyLNYmYnA3cAo4DOUXMVsASYfeBc9RBk41jogmsNmNlJZnaXma0zsw/MrNrM/mJmE+KuLdMOMxbj464t05LGYm3o/y6AhcAeYIi7d3T3jsBFJM5seirWyjIv68ZCR/oNmNkSYDGwHLiaxHz2fOCfSMzj/mOM5WWUxqKexqKemW1093Oau+5YlI1jodBvwMxWu3tx0nKZu/c3sxxgfUgf2Gks6mks6pnZH0i8+T1x4FpEZtYFmABc4u5/F2N5GZWNY6HpnUPtM7NvAZjZ5cDfANx9P4lP5kOisainsaj3PaAj8LKZ7TGzvwEvAR1I/BUUkqwbC52nf6j/BTxiZv8DWAtMhLqr5j0YZ2Ex0FjU01hEossGPwYsA/7i7h8dWGdmw0mc1huEbBwLTe80g5nd4O6PxV1Ha6CxqBfaWJjZ3wO3AhuAPsBt7r4kWvemu/eNs75MysaxUOg3gwV2h6TD0VjUC20szGwNcL67fxRdhO9p4Lfu/oumvtx4rMrGsdD0TgNm1tQVNg3oksla4qaxqKexOEjugWkMd99qZkOAp83sTML7fCPrxkKhf6guwDAS594mM+DPmS8nVhqLehqLev9lZn3cvQIgOsq9jMR1aIriLS3jsm4sFPqHehY46cAvMZmZvZT5cmKlsainsah3PYnrMNVx9xrgejP7v/GUFJusGwvN6YuIBETn6YuIBEShLyISEIW+iEhAFPoiIgFR6IuIBOS/Aa0blZl1cWs0AAAAAElFTkSuQmCC\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], "source": [ "## FOURTH VERSION OF SCRIPT\n", "\n", @@ -723,14 +2646,15 @@ " \n", " return ratio * x['2009'] / ratio2009\n", "\n", - "filled_df = stacked_df.*****(calculate_prices_in_todays_money_for_row, ****=*)\n", + "filled_df = stacked_df.apply(calculate_prices_in_todays_money_for_row, axis=1)\n", "\n", "# [J]\n", "# You only need this line in Jupyter\n", "%matplotlib inline\n", "\n", "transposed_df = filled_df.transpose()\n", - "transposed_df[\"Communication\"].plot(kind='bar')" + "transposed_df[\"Communication\"].plot(kind='bar')\n", + "transposed_df[\"Communication\"]" ] }, { @@ -748,7 +2672,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 51, "metadata": { "slideshow": { "slide_type": "slide" @@ -768,26 +2692,206 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 52, "metadata": { "slideshow": { "slide_type": "slide" } }, - "outputs": [], + "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", + "
19711981199120012009
Category
Food and non-alcoholic beverages100.0104.640913117.230576136.729755151.008988
Alcoholic beverages and tobacco100.099.23749792.06420488.02422189.613302
Clothing and footwear100.0119.877158186.847400344.276183552.546860
Housing, water and fuels2100.0116.734336138.879523152.250032160.082001
Furnishings, household equipment and maintenance100.0116.808722159.656426261.638586262.682524
\n", + "
" + ], + "text/plain": [ + " 1971 1981 \\\n", + "Category \n", + "Food and non-alcoholic beverages 100.0 104.640913 \n", + "Alcoholic beverages and tobacco 100.0 99.237497 \n", + "Clothing and footwear 100.0 119.877158 \n", + "Housing, water and fuels2 100.0 116.734336 \n", + "Furnishings, household equipment and maintenance 100.0 116.808722 \n", + "\n", + " 1991 2001 \\\n", + "Category \n", + "Food and non-alcoholic beverages 117.230576 136.729755 \n", + "Alcoholic beverages and tobacco 92.064204 88.024221 \n", + "Clothing and footwear 186.847400 344.276183 \n", + "Housing, water and fuels2 138.879523 152.250032 \n", + "Furnishings, household equipment and maintenance 159.656426 261.638586 \n", + "\n", + " 2009 \n", + "Category \n", + "Food and non-alcoholic beverages 151.008988 \n", + "Alcoholic beverages and tobacco 89.613302 \n", + "Clothing and footwear 552.546860 \n", + "Housing, water and fuels2 160.082001 \n", + "Furnishings, household equipment and maintenance 262.682524 " + ] + }, + "execution_count": 52, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "perc1971.head()" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 53, "metadata": { "slideshow": { "slide_type": "fragment" } }, - "outputs": [], + "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", + "
2009
Category
Food and non-alcoholic beverages83.813
Alcoholic beverages and tobacco31.128
Clothing and footwear47.599
Housing, water and fuels2193.447
Furnishings, household equipment and maintenance43.867
\n", + "
" + ], + "text/plain": [ + " 2009\n", + "Category \n", + "Food and non-alcoholic beverages 83.813\n", + "Alcoholic beverages and tobacco 31.128\n", + "Clothing and footwear 47.599\n", + "Housing, water and fuels2 193.447\n", + "Furnishings, household equipment and maintenance 43.867" + ] + }, + "execution_count": 53, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "todaysCurrency.head()" ] @@ -805,13 +2909,584 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 55, + "metadata": {}, + "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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
197119811991200120092009.1
Category
Food and non-alcoholic beverages100.0104.640913117.230576136.729755151.00898883.813
Alcoholic beverages and tobacco100.099.23749792.06420488.02422189.61330231.128
Clothing and footwear100.0119.877158186.847400344.276183552.54686047.599
Housing, water and fuels2100.0116.734336138.879523152.250032160.082001193.447
Furnishings, household equipment and maintenance100.0116.808722159.656426261.638586262.68252443.867
Miscellaneous goods and services100.0120.876377240.394746336.047068377.225149104.765
Restaurants and hotels3100.0125.594386167.157564193.105120185.49466888.763
Recreation and culture100.0158.242026279.165652544.963883868.80935099.260
Transport100.0127.948926180.949507246.488683272.763784124.616
Communication100.0190.027855306.406685789.5821731126.12813418.747
Health100.0124.598291182.273504187.760684229.26495714.283
Education100.0160.173877199.316912254.936866221.87952813.024
Total domestic household expenditure100.0120.735811166.460085225.223993259.495168863.312
Total goods100.0116.882766155.755787226.782179285.454027411.727
Total services100.0127.667167183.960495230.874717244.720566451.585
UK tourist expenditure abroad100.0193.380615298.082480699.054374576.33307128.994
less foreign tourist expenditure100.0151.616612187.182066222.215836257.81003019.554
Household final consumption expenditure4100.0121.341138168.287800232.291680264.930072872.752
\n", + "
" + ], + "text/plain": [ + " 1971 1981 \\\n", + "Category \n", + "Food and non-alcoholic beverages 100.0 104.640913 \n", + "Alcoholic beverages and tobacco 100.0 99.237497 \n", + "Clothing and footwear 100.0 119.877158 \n", + "Housing, water and fuels2 100.0 116.734336 \n", + "Furnishings, household equipment and maintenance 100.0 116.808722 \n", + "Miscellaneous goods and services 100.0 120.876377 \n", + "Restaurants and hotels3 100.0 125.594386 \n", + "Recreation and culture 100.0 158.242026 \n", + "Transport 100.0 127.948926 \n", + "Communication 100.0 190.027855 \n", + "Health 100.0 124.598291 \n", + "Education 100.0 160.173877 \n", + "Total domestic household expenditure 100.0 120.735811 \n", + " Total goods 100.0 116.882766 \n", + " Total services 100.0 127.667167 \n", + "UK tourist expenditure abroad 100.0 193.380615 \n", + " less foreign tourist expenditure 100.0 151.616612 \n", + "Household final consumption expenditure4 100.0 121.341138 \n", + "\n", + " 1991 2001 \\\n", + "Category \n", + "Food and non-alcoholic beverages 117.230576 136.729755 \n", + "Alcoholic beverages and tobacco 92.064204 88.024221 \n", + "Clothing and footwear 186.847400 344.276183 \n", + "Housing, water and fuels2 138.879523 152.250032 \n", + "Furnishings, household equipment and maintenance 159.656426 261.638586 \n", + "Miscellaneous goods and services 240.394746 336.047068 \n", + "Restaurants and hotels3 167.157564 193.105120 \n", + "Recreation and culture 279.165652 544.963883 \n", + "Transport 180.949507 246.488683 \n", + "Communication 306.406685 789.582173 \n", + "Health 182.273504 187.760684 \n", + "Education 199.316912 254.936866 \n", + "Total domestic household expenditure 166.460085 225.223993 \n", + " Total goods 155.755787 226.782179 \n", + " Total services 183.960495 230.874717 \n", + "UK tourist expenditure abroad 298.082480 699.054374 \n", + " less foreign tourist expenditure 187.182066 222.215836 \n", + "Household final consumption expenditure4 168.287800 232.291680 \n", + "\n", + " 2009 2009.1 \n", + "Category \n", + "Food and non-alcoholic beverages 151.008988 83.813 \n", + "Alcoholic beverages and tobacco 89.613302 31.128 \n", + "Clothing and footwear 552.546860 47.599 \n", + "Housing, water and fuels2 160.082001 193.447 \n", + "Furnishings, household equipment and maintenance 262.682524 43.867 \n", + "Miscellaneous goods and services 377.225149 104.765 \n", + "Restaurants and hotels3 185.494668 88.763 \n", + "Recreation and culture 868.809350 99.260 \n", + "Transport 272.763784 124.616 \n", + "Communication 1126.128134 18.747 \n", + "Health 229.264957 14.283 \n", + "Education 221.879528 13.024 \n", + "Total domestic household expenditure 259.495168 863.312 \n", + " Total goods 285.454027 411.727 \n", + " Total services 244.720566 451.585 \n", + "UK tourist expenditure abroad 576.333071 28.994 \n", + " less foreign tourist expenditure 257.810030 19.554 \n", + "Household final consumption expenditure4 264.930072 872.752 " + ] + }, + "execution_count": 55, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df" + ] + }, + { + "cell_type": "code", + "execution_count": 54, "metadata": { "slideshow": { "slide_type": "slide" } }, - "outputs": [], + "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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
%1971today's money
197119811991200120092009
Category
Food and non-alcoholic beverages100.0104.640913117.230576136.729755151.00898883.813
Alcoholic beverages and tobacco100.099.23749792.06420488.02422189.61330231.128
Clothing and footwear100.0119.877158186.847400344.276183552.54686047.599
Housing, water and fuels2100.0116.734336138.879523152.250032160.082001193.447
Furnishings, household equipment and maintenance100.0116.808722159.656426261.638586262.68252443.867
Miscellaneous goods and services100.0120.876377240.394746336.047068377.225149104.765
Restaurants and hotels3100.0125.594386167.157564193.105120185.49466888.763
Recreation and culture100.0158.242026279.165652544.963883868.80935099.260
Transport100.0127.948926180.949507246.488683272.763784124.616
Communication100.0190.027855306.406685789.5821731126.12813418.747
Health100.0124.598291182.273504187.760684229.26495714.283
Education100.0160.173877199.316912254.936866221.87952813.024
Total domestic household expenditure100.0120.735811166.460085225.223993259.495168863.312
Total goods100.0116.882766155.755787226.782179285.454027411.727
Total services100.0127.667167183.960495230.874717244.720566451.585
UK tourist expenditure abroad100.0193.380615298.082480699.054374576.33307128.994
less foreign tourist expenditure100.0151.616612187.182066222.215836257.81003019.554
Household final consumption expenditure4100.0121.341138168.287800232.291680264.930072872.752
\n", + "
" + ], + "text/plain": [ + " %1971 \\\n", + " 1971 1981 \n", + "Category \n", + "Food and non-alcoholic beverages 100.0 104.640913 \n", + "Alcoholic beverages and tobacco 100.0 99.237497 \n", + "Clothing and footwear 100.0 119.877158 \n", + "Housing, water and fuels2 100.0 116.734336 \n", + "Furnishings, household equipment and maintenance 100.0 116.808722 \n", + "Miscellaneous goods and services 100.0 120.876377 \n", + "Restaurants and hotels3 100.0 125.594386 \n", + "Recreation and culture 100.0 158.242026 \n", + "Transport 100.0 127.948926 \n", + "Communication 100.0 190.027855 \n", + "Health 100.0 124.598291 \n", + "Education 100.0 160.173877 \n", + "Total domestic household expenditure 100.0 120.735811 \n", + " Total goods 100.0 116.882766 \n", + " Total services 100.0 127.667167 \n", + "UK tourist expenditure abroad 100.0 193.380615 \n", + " less foreign tourist expenditure 100.0 151.616612 \n", + "Household final consumption expenditure4 100.0 121.341138 \n", + "\n", + " \\\n", + " 1991 2001 \n", + "Category \n", + "Food and non-alcoholic beverages 117.230576 136.729755 \n", + "Alcoholic beverages and tobacco 92.064204 88.024221 \n", + "Clothing and footwear 186.847400 344.276183 \n", + "Housing, water and fuels2 138.879523 152.250032 \n", + "Furnishings, household equipment and maintenance 159.656426 261.638586 \n", + "Miscellaneous goods and services 240.394746 336.047068 \n", + "Restaurants and hotels3 167.157564 193.105120 \n", + "Recreation and culture 279.165652 544.963883 \n", + "Transport 180.949507 246.488683 \n", + "Communication 306.406685 789.582173 \n", + "Health 182.273504 187.760684 \n", + "Education 199.316912 254.936866 \n", + "Total domestic household expenditure 166.460085 225.223993 \n", + " Total goods 155.755787 226.782179 \n", + " Total services 183.960495 230.874717 \n", + "UK tourist expenditure abroad 298.082480 699.054374 \n", + " less foreign tourist expenditure 187.182066 222.215836 \n", + "Household final consumption expenditure4 168.287800 232.291680 \n", + "\n", + " today's money \n", + " 2009 2009 \n", + "Category \n", + "Food and non-alcoholic beverages 151.008988 83.813 \n", + "Alcoholic beverages and tobacco 89.613302 31.128 \n", + "Clothing and footwear 552.546860 47.599 \n", + "Housing, water and fuels2 160.082001 193.447 \n", + "Furnishings, household equipment and maintenance 262.682524 43.867 \n", + "Miscellaneous goods and services 377.225149 104.765 \n", + "Restaurants and hotels3 185.494668 88.763 \n", + "Recreation and culture 868.809350 99.260 \n", + "Transport 272.763784 124.616 \n", + "Communication 1126.128134 18.747 \n", + "Health 229.264957 14.283 \n", + "Education 221.879528 13.024 \n", + "Total domestic household expenditure 259.495168 863.312 \n", + " Total goods 285.454027 411.727 \n", + " Total services 244.720566 451.585 \n", + "UK tourist expenditure abroad 576.333071 28.994 \n", + " less foreign tourist expenditure 257.810030 19.554 \n", + "Household final consumption expenditure4 264.930072 872.752 " + ] + }, + "execution_count": 54, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "joined_df = pd.concat((perc1971, todaysCurrency), axis=1, keys=(\"%1971\", \"today's money\")) # [G]\n", "joined_df" @@ -856,13 +3531,392 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 56, "metadata": { "slideshow": { "slide_type": "slide" } }, - "outputs": [], + "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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
%1971today's money
Category
Food and non-alcoholic beverages1971100.000000NaN
1981104.640913NaN
1991117.230576NaN
2001136.729755NaN
2009151.00898883.813
Alcoholic beverages and tobacco1971100.000000NaN
198199.237497NaN
199192.064204NaN
200188.024221NaN
200989.61330231.128
Clothing and footwear1971100.000000NaN
1981119.877158NaN
1991186.847400NaN
2001344.276183NaN
2009552.54686047.599
Housing, water and fuels21971100.000000NaN
1981116.734336NaN
1991138.879523NaN
2001152.250032NaN
2009160.082001193.447
Furnishings, household equipment and maintenance1971100.000000NaN
1981116.808722NaN
1991159.656426NaN
2001261.638586NaN
2009262.68252443.867
Miscellaneous goods and services1971100.000000NaN
1981120.876377NaN
1991240.394746NaN
2001336.047068NaN
2009377.225149104.765
............
Total domestic household expenditure1971100.000000NaN
1981120.735811NaN
1991166.460085NaN
2001225.223993NaN
2009259.495168863.312
Total goods1971100.000000NaN
1981116.882766NaN
1991155.755787NaN
2001226.782179NaN
2009285.454027411.727
Total services1971100.000000NaN
1981127.667167NaN
1991183.960495NaN
2001230.874717NaN
2009244.720566451.585
UK tourist expenditure abroad1971100.000000NaN
1981193.380615NaN
1991298.082480NaN
2001699.054374NaN
2009576.33307128.994
less foreign tourist expenditure1971100.000000NaN
1981151.616612NaN
1991187.182066NaN
2001222.215836NaN
2009257.81003019.554
Household final consumption expenditure41971100.000000NaN
1981121.341138NaN
1991168.287800NaN
2001232.291680NaN
2009264.930072872.752
\n", + "

90 rows × 2 columns

\n", + "
" + ], + "text/plain": [ + " %1971 today's money\n", + "Category \n", + "Food and non-alcoholic beverages 1971 100.000000 NaN\n", + " 1981 104.640913 NaN\n", + " 1991 117.230576 NaN\n", + " 2001 136.729755 NaN\n", + " 2009 151.008988 83.813\n", + "... ... ...\n", + "Household final consumption expenditure4 1971 100.000000 NaN\n", + " 1981 121.341138 NaN\n", + " 1991 168.287800 NaN\n", + " 2001 232.291680 NaN\n", + " 2009 264.930072 872.752\n", + "\n", + "[90 rows x 2 columns]" + ] + }, + "execution_count": 56, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "joined_df.stack()" ] @@ -880,13 +3934,564 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 57, "metadata": { "slideshow": { "slide_type": "slide" } }, - "outputs": [], + "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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
19711981199120012009
Category
Food and non-alcoholic beverages%1971100.0104.640913117.230576136.729755151.008988
today's moneyNaNNaNNaNNaN83.813000
Alcoholic beverages and tobacco%1971100.099.23749792.06420488.02422189.613302
today's moneyNaNNaNNaNNaN31.128000
Clothing and footwear%1971100.0119.877158186.847400344.276183552.546860
today's moneyNaNNaNNaNNaN47.599000
Housing, water and fuels2%1971100.0116.734336138.879523152.250032160.082001
today's moneyNaNNaNNaNNaN193.447000
Furnishings, household equipment and maintenance%1971100.0116.808722159.656426261.638586262.682524
today's moneyNaNNaNNaNNaN43.867000
Miscellaneous goods and services%1971100.0120.876377240.394746336.047068377.225149
today's moneyNaNNaNNaNNaN104.765000
Restaurants and hotels3%1971100.0125.594386167.157564193.105120185.494668
today's moneyNaNNaNNaNNaN88.763000
Recreation and culture%1971100.0158.242026279.165652544.963883868.809350
today's moneyNaNNaNNaNNaN99.260000
Transport%1971100.0127.948926180.949507246.488683272.763784
today's moneyNaNNaNNaNNaN124.616000
Communication%1971100.0190.027855306.406685789.5821731126.128134
today's moneyNaNNaNNaNNaN18.747000
Health%1971100.0124.598291182.273504187.760684229.264957
today's moneyNaNNaNNaNNaN14.283000
Education%1971100.0160.173877199.316912254.936866221.879528
today's moneyNaNNaNNaNNaN13.024000
Total domestic household expenditure%1971100.0120.735811166.460085225.223993259.495168
today's moneyNaNNaNNaNNaN863.312000
Total goods%1971100.0116.882766155.755787226.782179285.454027
today's moneyNaNNaNNaNNaN411.727000
Total services%1971100.0127.667167183.960495230.874717244.720566
today's moneyNaNNaNNaNNaN451.585000
UK tourist expenditure abroad%1971100.0193.380615298.082480699.054374576.333071
today's moneyNaNNaNNaNNaN28.994000
less foreign tourist expenditure%1971100.0151.616612187.182066222.215836257.810030
today's moneyNaNNaNNaNNaN19.554000
Household final consumption expenditure4%1971100.0121.341138168.287800232.291680264.930072
today's moneyNaNNaNNaNNaN872.752000
\n", + "
" + ], + "text/plain": [ + " 1971 \\\n", + "Category \n", + "Food and non-alcoholic beverages %1971 100.0 \n", + " today's money NaN \n", + "Alcoholic beverages and tobacco %1971 100.0 \n", + " today's money NaN \n", + "Clothing and footwear %1971 100.0 \n", + " today's money NaN \n", + "Housing, water and fuels2 %1971 100.0 \n", + " today's money NaN \n", + "Furnishings, household equipment and maintenance %1971 100.0 \n", + " today's money NaN \n", + "Miscellaneous goods and services %1971 100.0 \n", + " today's money NaN \n", + "Restaurants and hotels3 %1971 100.0 \n", + " today's money NaN \n", + "Recreation and culture %1971 100.0 \n", + " today's money NaN \n", + "Transport %1971 100.0 \n", + " today's money NaN \n", + "Communication %1971 100.0 \n", + " today's money NaN \n", + "Health %1971 100.0 \n", + " today's money NaN \n", + "Education %1971 100.0 \n", + " today's money NaN \n", + "Total domestic household expenditure %1971 100.0 \n", + " today's money NaN \n", + " Total goods %1971 100.0 \n", + " today's money NaN \n", + " Total services %1971 100.0 \n", + " today's money NaN \n", + "UK tourist expenditure abroad %1971 100.0 \n", + " today's money NaN \n", + " less foreign tourist expenditure %1971 100.0 \n", + " today's money NaN \n", + "Household final consumption expenditure4 %1971 100.0 \n", + " today's money NaN \n", + "\n", + " 1981 \\\n", + "Category \n", + "Food and non-alcoholic beverages %1971 104.640913 \n", + " today's money NaN \n", + "Alcoholic beverages and tobacco %1971 99.237497 \n", + " today's money NaN \n", + "Clothing and footwear %1971 119.877158 \n", + " today's money NaN \n", + "Housing, water and fuels2 %1971 116.734336 \n", + " today's money NaN \n", + "Furnishings, household equipment and maintenance %1971 116.808722 \n", + " today's money NaN \n", + "Miscellaneous goods and services %1971 120.876377 \n", + " today's money NaN \n", + "Restaurants and hotels3 %1971 125.594386 \n", + " today's money NaN \n", + "Recreation and culture %1971 158.242026 \n", + " today's money NaN \n", + "Transport %1971 127.948926 \n", + " today's money NaN \n", + "Communication %1971 190.027855 \n", + " today's money NaN \n", + "Health %1971 124.598291 \n", + " today's money NaN \n", + "Education %1971 160.173877 \n", + " today's money NaN \n", + "Total domestic household expenditure %1971 120.735811 \n", + " today's money NaN \n", + " Total goods %1971 116.882766 \n", + " today's money NaN \n", + " Total services %1971 127.667167 \n", + " today's money NaN \n", + "UK tourist expenditure abroad %1971 193.380615 \n", + " today's money NaN \n", + " less foreign tourist expenditure %1971 151.616612 \n", + " today's money NaN \n", + "Household final consumption expenditure4 %1971 121.341138 \n", + " today's money NaN \n", + "\n", + " 1991 \\\n", + "Category \n", + "Food and non-alcoholic beverages %1971 117.230576 \n", + " today's money NaN \n", + "Alcoholic beverages and tobacco %1971 92.064204 \n", + " today's money NaN \n", + "Clothing and footwear %1971 186.847400 \n", + " today's money NaN \n", + "Housing, water and fuels2 %1971 138.879523 \n", + " today's money NaN \n", + "Furnishings, household equipment and maintenance %1971 159.656426 \n", + " today's money NaN \n", + "Miscellaneous goods and services %1971 240.394746 \n", + " today's money NaN \n", + "Restaurants and hotels3 %1971 167.157564 \n", + " today's money NaN \n", + "Recreation and culture %1971 279.165652 \n", + " today's money NaN \n", + "Transport %1971 180.949507 \n", + " today's money NaN \n", + "Communication %1971 306.406685 \n", + " today's money NaN \n", + "Health %1971 182.273504 \n", + " today's money NaN \n", + "Education %1971 199.316912 \n", + " today's money NaN \n", + "Total domestic household expenditure %1971 166.460085 \n", + " today's money NaN \n", + " Total goods %1971 155.755787 \n", + " today's money NaN \n", + " Total services %1971 183.960495 \n", + " today's money NaN \n", + "UK tourist expenditure abroad %1971 298.082480 \n", + " today's money NaN \n", + " less foreign tourist expenditure %1971 187.182066 \n", + " today's money NaN \n", + "Household final consumption expenditure4 %1971 168.287800 \n", + " today's money NaN \n", + "\n", + " 2001 \\\n", + "Category \n", + "Food and non-alcoholic beverages %1971 136.729755 \n", + " today's money NaN \n", + "Alcoholic beverages and tobacco %1971 88.024221 \n", + " today's money NaN \n", + "Clothing and footwear %1971 344.276183 \n", + " today's money NaN \n", + "Housing, water and fuels2 %1971 152.250032 \n", + " today's money NaN \n", + "Furnishings, household equipment and maintenance %1971 261.638586 \n", + " today's money NaN \n", + "Miscellaneous goods and services %1971 336.047068 \n", + " today's money NaN \n", + "Restaurants and hotels3 %1971 193.105120 \n", + " today's money NaN \n", + "Recreation and culture %1971 544.963883 \n", + " today's money NaN \n", + "Transport %1971 246.488683 \n", + " today's money NaN \n", + "Communication %1971 789.582173 \n", + " today's money NaN \n", + "Health %1971 187.760684 \n", + " today's money NaN \n", + "Education %1971 254.936866 \n", + " today's money NaN \n", + "Total domestic household expenditure %1971 225.223993 \n", + " today's money NaN \n", + " Total goods %1971 226.782179 \n", + " today's money NaN \n", + " Total services %1971 230.874717 \n", + " today's money NaN \n", + "UK tourist expenditure abroad %1971 699.054374 \n", + " today's money NaN \n", + " less foreign tourist expenditure %1971 222.215836 \n", + " today's money NaN \n", + "Household final consumption expenditure4 %1971 232.291680 \n", + " today's money NaN \n", + "\n", + " 2009 \n", + "Category \n", + "Food and non-alcoholic beverages %1971 151.008988 \n", + " today's money 83.813000 \n", + "Alcoholic beverages and tobacco %1971 89.613302 \n", + " today's money 31.128000 \n", + "Clothing and footwear %1971 552.546860 \n", + " today's money 47.599000 \n", + "Housing, water and fuels2 %1971 160.082001 \n", + " today's money 193.447000 \n", + "Furnishings, household equipment and maintenance %1971 262.682524 \n", + " today's money 43.867000 \n", + "Miscellaneous goods and services %1971 377.225149 \n", + " today's money 104.765000 \n", + "Restaurants and hotels3 %1971 185.494668 \n", + " today's money 88.763000 \n", + "Recreation and culture %1971 868.809350 \n", + " today's money 99.260000 \n", + "Transport %1971 272.763784 \n", + " today's money 124.616000 \n", + "Communication %1971 1126.128134 \n", + " today's money 18.747000 \n", + "Health %1971 229.264957 \n", + " today's money 14.283000 \n", + "Education %1971 221.879528 \n", + " today's money 13.024000 \n", + "Total domestic household expenditure %1971 259.495168 \n", + " today's money 863.312000 \n", + " Total goods %1971 285.454027 \n", + " today's money 411.727000 \n", + " Total services %1971 244.720566 \n", + " today's money 451.585000 \n", + "UK tourist expenditure abroad %1971 576.333071 \n", + " today's money 28.994000 \n", + " less foreign tourist expenditure %1971 257.810030 \n", + " today's money 19.554000 \n", + "Household final consumption expenditure4 %1971 264.930072 \n", + " today's money 872.752000 " + ] + }, + "execution_count": 57, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "stacked_df = joined_df.stack(level=0) # [H]\n", "stacked_df" @@ -986,7 +4591,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 58, "metadata": { "slideshow": { "slide_type": "slide" @@ -1113,14 +4718,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 66, "metadata": { "scrolled": true, "slideshow": { "slide_type": "notes" } }, - "outputs": [], + "outputs": [ + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZsAAAEWCAYAAACwtjr+AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAZfElEQVR4nO3de7TdZX3n8ffHxEs44gBaKDcFZzJYoBU1Rp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3An8zzU8sBD6fZHc6/7H706p6tP2eS3OPV6NJklrnYTRJUusMG0lS6wwbSVLrDBtJUusMG0lS6wwbSVLrDBtJUusMG0lS6/4/5Pno1lt/9w8AAAAASUVORK5CYII=\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], "source": [ "## FIFTH VERSION OF SCRIPT\n", "\n", @@ -1270,13 +4888,454 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 67, "metadata": { "slideshow": { "slide_type": "slide" } }, - "outputs": [], + "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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
HARMONIZED CPI (INDEX NUMBER)CPI: ALL ITEMS (INDEX NUMBER)CPI % CHANGE (PERCENT PER ANNU)
Date
1948-12-31NaN4.42594NaN
1949-12-31NaN4.565343.149610
1950-12-31NaN4.669892.290080
1951-12-31NaN5.122949.701490
1952-12-31NaN5.436596.122450
1953-12-31NaN5.541141.923080
1954-12-31NaN5.645691.886790
1955-12-31NaN5.819943.086420
1956-12-31NaN6.063884.191620
1957-12-31NaN6.206192.346740
1958-12-31NaN6.383342.854470
1959-12-31NaN6.426900.682439
1960-12-31NaN6.490800.994126
1961-12-31NaN6.723133.579420
1962-12-31NaN6.999024.103670
1963-12-31NaN7.144232.074690
1964-12-31NaN7.373663.211380
1965-12-31NaN7.727974.805040
1966-12-31NaN8.030003.908310
1967-12-31NaN8.224582.423150
1968-12-31NaN8.613744.731640
1969-12-31NaN9.084215.461900
1970-12-31NaN9.662146.361890
1971-12-31NaN10.571109.407870
1972-12-31NaN11.320407.087910
1973-12-31NaN12.363009.209850
1974-12-31NaN14.3291015.903200
1975-12-31NaN17.8018024.235100
1976-12-31NaN20.7449016.532600
1977-12-31NaN24.0396015.882000
............
1980-12-31NaN34.8222017.970600
1981-12-31NaN38.9591011.879800
1982-12-31NaN42.305908.590530
1983-12-31NaN44.254904.607020
1984-12-31NaN46.447004.953410
1985-12-31NaN49.264206.065420
1986-12-31NaN50.952803.427610
1987-12-31NaN53.066804.148920
1988-12-3163.491155.671304.907980
1989-12-3166.795360.012207.797270
1990-12-3171.487265.698709.475590
1991-12-3176.869369.544605.853980
1992-12-3180.122072.140503.732600
1993-12-3182.148673.269101.564470
1994-12-3183.771375.083602.476450
1995-12-3185.988777.644703.411000
1996-12-3188.110779.545902.448710
1997-12-3189.704182.037603.132330
1998-12-3191.106584.841803.418170
1999-12-3192.332786.161401.555390
2000-12-3193.057888.683402.927100
2001-12-3194.207990.298201.820850
2002-12-3195.391391.774101.634460
2003-12-3196.691494.448102.913630
2004-12-3197.991597.247902.964430
2005-12-31100.0000100.000002.829980
2006-12-31102.3340103.195003.194860
2007-12-31104.7090107.605004.273760
2008-12-31108.4920111.903003.993710
2009-12-31110.8430111.28200-0.554715
\n", + "

62 rows × 3 columns

\n", + "
" + ], + "text/plain": [ + " HARMONIZED CPI (INDEX NUMBER) CPI: ALL ITEMS (INDEX NUMBER) \\\n", + "Date \n", + "1948-12-31 NaN 4.42594 \n", + "1949-12-31 NaN 4.56534 \n", + "1950-12-31 NaN 4.66989 \n", + "1951-12-31 NaN 5.12294 \n", + "1952-12-31 NaN 5.43659 \n", + "... ... ... \n", + "2005-12-31 100.000 100.00000 \n", + "2006-12-31 102.334 103.19500 \n", + "2007-12-31 104.709 107.60500 \n", + "2008-12-31 108.492 111.90300 \n", + "2009-12-31 110.843 111.28200 \n", + "\n", + " CPI % CHANGE (PERCENT PER ANNU) \n", + "Date \n", + "1948-12-31 NaN \n", + "1949-12-31 3.149610 \n", + "1950-12-31 2.290080 \n", + "1951-12-31 9.701490 \n", + "1952-12-31 6.122450 \n", + "... ... \n", + "2005-12-31 2.829980 \n", + "2006-12-31 3.194860 \n", + "2007-12-31 4.273760 \n", + "2008-12-31 3.993710 \n", + "2009-12-31 -0.554715 \n", + "\n", + "[62 rows x 3 columns]" + ] + }, + "execution_count": 67, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "import quandl\n", "cpi = quandl.get(\"UIFS/CPI_GBR\", returns=\"pandas\")\n", From 138c1510e3693ba969cd011f31ae957caf8d5a75 Mon Sep 17 00:00:00 2001 From: nbgitpuller Date: Thu, 4 Jun 2020 08:13:16 +0000 Subject: [PATCH 2/6] Automatic commit by nbgitpuller From 7ab5e117415fb7465d9d8f5f165cdbafe8c62a3f Mon Sep 17 00:00:00 2001 From: nbgitpuller Date: Wed, 10 Jun 2020 08:09:45 +0000 Subject: [PATCH 3/6] Automatic commit by nbgitpuller --- 018-bioinformatics/Words Apart.ipynb | 28 +++++++++++++------------- 018-bioinformatics/test_levenshtein.py | 4 ++-- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/018-bioinformatics/Words Apart.ipynb b/018-bioinformatics/Words Apart.ipynb index cc2cd4a..ad609ea 100644 --- a/018-bioinformatics/Words Apart.ipynb +++ b/018-bioinformatics/Words Apart.ipynb @@ -156,7 +156,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -167,18 +167,18 @@ "Requirement already satisfied: pytest in /opt/conda/lib/python3.7/site-packages (from -r requirements.txt (line 2)) (5.4.3)\n", "Requirement already satisfied: pytest-benchmark==3.2.* in /opt/conda/lib/python3.7/site-packages (from -r requirements.txt (line 3)) (3.2.3)\n", "Requirement already satisfied: python-levenshtein<0.13,>=0.10 in /opt/conda/lib/python3.7/site-packages (from -r requirements.txt (line 4)) (0.12.0)\n", + "Requirement already satisfied: more-itertools>=4.0.0 in /opt/conda/lib/python3.7/site-packages (from pytest->-r requirements.txt (line 2)) (8.3.0)\n", "Requirement already satisfied: wcwidth in /opt/conda/lib/python3.7/site-packages (from pytest->-r requirements.txt (line 2)) (0.1.7)\n", - "Requirement already satisfied: importlib-metadata>=0.12; python_version < \"3.8\" in /opt/conda/lib/python3.7/site-packages (from pytest->-r requirements.txt (line 2)) (1.6.0)\n", "Requirement already satisfied: pluggy<1.0,>=0.12 in /opt/conda/lib/python3.7/site-packages (from pytest->-r requirements.txt (line 2)) (0.13.1)\n", - "Requirement already satisfied: packaging in /opt/conda/lib/python3.7/site-packages (from pytest->-r requirements.txt (line 2)) (19.0)\n", - "Requirement already satisfied: more-itertools>=4.0.0 in /opt/conda/lib/python3.7/site-packages (from pytest->-r requirements.txt (line 2)) (8.3.0)\n", - "Requirement already satisfied: attrs>=17.4.0 in /opt/conda/lib/python3.7/site-packages (from pytest->-r requirements.txt (line 2)) (19.1.0)\n", "Requirement already satisfied: py>=1.5.0 in /opt/conda/lib/python3.7/site-packages (from pytest->-r requirements.txt (line 2)) (1.8.1)\n", + "Requirement already satisfied: importlib-metadata>=0.12; python_version < \"3.8\" in /opt/conda/lib/python3.7/site-packages (from pytest->-r requirements.txt (line 2)) (1.6.0)\n", + "Requirement already satisfied: attrs>=17.4.0 in /opt/conda/lib/python3.7/site-packages (from pytest->-r requirements.txt (line 2)) (19.1.0)\n", + "Requirement already satisfied: packaging in /opt/conda/lib/python3.7/site-packages (from pytest->-r requirements.txt (line 2)) (19.0)\n", "Requirement already satisfied: py-cpuinfo in /opt/conda/lib/python3.7/site-packages (from pytest-benchmark==3.2.*->-r requirements.txt (line 3)) (5.0.0)\n", "Requirement already satisfied: setuptools in /opt/conda/lib/python3.7/site-packages (from python-levenshtein<0.13,>=0.10->-r requirements.txt (line 4)) (41.0.1)\n", "Requirement already satisfied: zipp>=0.5 in /opt/conda/lib/python3.7/site-packages (from importlib-metadata>=0.12; python_version < \"3.8\"->pytest->-r requirements.txt (line 2)) (3.1.0)\n", - "Requirement already satisfied: six in /opt/conda/lib/python3.7/site-packages (from packaging->pytest->-r requirements.txt (line 2)) (1.12.0)\n", - "Requirement already satisfied: pyparsing>=2.0.2 in /opt/conda/lib/python3.7/site-packages (from packaging->pytest->-r requirements.txt (line 2)) (2.4.2)\n" + "Requirement already satisfied: pyparsing>=2.0.2 in /opt/conda/lib/python3.7/site-packages (from packaging->pytest->-r requirements.txt (line 2)) (2.4.2)\n", + "Requirement already satisfied: six in /opt/conda/lib/python3.7/site-packages (from packaging->pytest->-r requirements.txt (line 2)) (1.12.0)\n" ] } ], @@ -236,7 +236,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -244,7 +244,7 @@ "output_type": "stream", "text": [ "\u001b[1m============================= test session starts ==============================\u001b[0m\n", - "platform linux -- Python 3.7.3, pytest-5.4.2, py-1.8.1, pluggy-0.13.1\n", + "platform linux -- Python 3.7.3, pytest-5.4.3, py-1.8.1, pluggy-0.13.1\n", "benchmark: 3.2.3 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)\n", "rootdir: /home/jovyan/python-course/018-bioinformatics\n", "plugins: benchmark-3.2.3\n", @@ -255,14 +255,14 @@ "=================================== FAILURES ===================================\n", "\u001b[31m\u001b[1m_________________ test_different_strings_have_correct_distance _________________\u001b[0m\n", "\n", - "string1 = 'ttcagttcctcgcctatccaaacagcagcgtgaggtgcaagggacaaaccgatagggttgacacgttatgactatctgagtcttcggggtacgaacgagttgaggtaattgacatgg...gttggcggtacgtacggtgcagcagtgacgcaggaccagattgagttactacgaagaaacctgcaggcagcctggctgttcccgtagtgtatccgtacggttcgggcttgggcagcaa'\n", - "string2 = 'ttcagttcctcgcctatccaaacagcagcgtgaggtgcaagggacaaaccgatagggttgacacgttatgactatctgagtcttcggggtacgaacgagttgaggtaattgacatgg...gttggcggtacgtacggtgcagcagtgacgcaggaccagattgagttactacgaagaaacctgcaggcagcctggctgttcccgtagtgtatccgtacggttcgggcttgggcagcaa'\n", + "string1 = 'agtctctgagggtaccggggagttgagcatatgctcgtgaccagactgaa'\n", + "string2 = 'agtctctgagggtaccgggtagttgagcatatgctcgtgaccagtctgaa'\n", "\n", " \u001b[94mdef\u001b[39;49;00m \u001b[92mtest_different_strings_have_correct_distance\u001b[39;49;00m(string1, string2):\n", " edit_distance = my_levenshtein.calculate_levenshtein(string1, string2)\n", "> \u001b[94massert\u001b[39;49;00m edit_distance == levenshtein_module.distance(string1, string2)\n", - "\u001b[1m\u001b[31mE AssertionError: assert 0 == 200\u001b[0m\n", - "\u001b[1m\u001b[31mE + where 200 = ('ttcagttcctcgcctatccaaacagcagcgtgaggtgcaagggacaaaccgatagggttgacacgttatgactatctgagtcttcggggtacgaacgagttgaggtaattgacatgg...gttggcggtacgtacggtgcagcagtgacgcaggaccagattgagttactacgaagaaacctgcaggcagcctggctgttcccgtagtgtatccgtacggttcgggcttgggcagcaa', 'ttcagttcctcgcctatccaaacagcagcgtgaggtgcaagggacaaaccgatagggttgacacgttatgactatctgagtcttcggggtacgaacgagttgaggtaattgacatgg...gttggcggtacgtacggtgcagcagtgacgcaggaccagattgagttactacgaagaaacctgcaggcagcctggctgttcccgtagtgtatccgtacggttcgggcttgggcagcaa')\u001b[0m\n", + "\u001b[1m\u001b[31mE AssertionError: assert 0 == 2\u001b[0m\n", + "\u001b[1m\u001b[31mE + where 2 = ('agtctctgagggtaccggggagttgagcatatgctcgtgaccagactgaa', 'agtctctgagggtaccgggtagttgagcatatgctcgtgaccagtctgaa')\u001b[0m\n", "\u001b[1m\u001b[31mE + where = levenshtein_module.distance\u001b[0m\n", "\n", "\u001b[1m\u001b[31mtest_levenshtein.py\u001b[0m:41: AssertionError\n", @@ -295,7 +295,7 @@ "FAILED test_levenshtein.py::test_asdf_asfd_distance_is_two - assert 0 == 2\n", "FAILED test_levenshtein.py::test_asf_asfd_distance_is_one - assert 0 == 1\n", "FAILED test_levenshtein.py::test_amazon_aazonia_distance_is_three - assert 0 ...\n", - "\u001b[31m========================= \u001b[31m\u001b[1m4 failed\u001b[0m, \u001b[32m1 passed\u001b[0m\u001b[31m in 5.90s\u001b[0m\u001b[31m ==========================\u001b[0m\n" + "\u001b[31m========================= \u001b[31m\u001b[1m4 failed\u001b[0m, \u001b[32m1 passed\u001b[0m\u001b[31m in 0.25s\u001b[0m\u001b[31m ==========================\u001b[0m\n" ] } ], diff --git a/018-bioinformatics/test_levenshtein.py b/018-bioinformatics/test_levenshtein.py index 5d8e8b8..fb96feb 100644 --- a/018-bioinformatics/test_levenshtein.py +++ b/018-bioinformatics/test_levenshtein.py @@ -5,8 +5,8 @@ import python_course_levenshtein_c import my_levenshtein -LEN = 50000 -MISTAKES = 200 +LEN = 5 +MISTAKES = 2 @pytest.fixture def string1(): From a2a6a6fcb076a4ddd786e2f9771efa4db129ed17 Mon Sep 17 00:00:00 2001 From: nbgitpuller Date: Wed, 10 Jun 2020 08:22:08 +0000 Subject: [PATCH 4/6] Automatic commit by nbgitpuller --- 006-latency/Latency.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/006-latency/Latency.ipynb b/006-latency/Latency.ipynb index a54925c..74f858b 100644 --- a/006-latency/Latency.ipynb +++ b/006-latency/Latency.ipynb @@ -1054,7 +1054,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.1" + "version": "3.7.3" }, "livereveal": { "theme": "beige", From 560be5f9ed12d8e136c627382091fbea4653d601 Mon Sep 17 00:00:00 2001 From: nbgitpuller Date: Tue, 30 Jun 2020 21:31:40 +0000 Subject: [PATCH 5/6] Automatic commit by nbgitpuller --- .../Basic control structures II.ipynb | 193 +++++++++++++++++- 020-patterns/Solid Ideas.ipynb | 142 ++++++++++++- 2 files changed, 319 insertions(+), 16 deletions(-) diff --git a/002-basic-control-structures/Basic control structures II.ipynb b/002-basic-control-structures/Basic control structures II.ipynb index f8b129e..303f131 100644 --- a/002-basic-control-structures/Basic control structures II.ipynb +++ b/002-basic-control-structures/Basic control structures II.ipynb @@ -2212,7 +2212,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": { "hideCode": false, "hidePrompt": false @@ -2235,12 +2235,187 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "hideCode": false, - "hidePrompt": false - }, - "outputs": [], + "execution_count": 4, + "metadata": { + "hideCode": false, + "hidePrompt": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2\n", + "3\n", + "5\n", + "7\n", + "11\n", + "13\n", + "17\n", + "19\n", + "23\n", + "29\n", + "31\n", + "37\n", + "41\n", + "43\n", + "47\n", + "53\n", + "59\n", + "61\n", + "67\n", + "71\n", + "73\n", + "79\n", + "83\n", + "89\n", + "97\n", + "101\n", + "103\n", + "107\n", + "109\n", + "113\n", + "127\n", + "131\n", + "137\n", + "139\n", + "149\n", + "151\n", + "157\n", + "163\n", + "167\n", + "173\n", + "179\n", + "181\n", + "191\n", + "193\n", + "197\n", + "199\n", + "211\n", + "223\n", + "227\n", + "229\n", + "233\n", + "239\n", + "241\n", + "251\n", + "257\n", + "263\n", + "269\n", + "271\n", + "277\n", + "281\n", + "283\n", + "293\n", + "307\n", + "311\n", + "313\n", + "317\n", + "331\n", + "337\n", + "347\n", + "349\n", + "353\n", + "359\n", + "367\n", + "373\n", + "379\n", + "383\n", + "389\n", + "397\n", + "401\n", + "409\n", + "419\n", + "421\n", + "431\n", + "433\n", + "439\n", + "443\n", + "449\n", + "457\n", + "461\n", + "463\n", + "467\n", + "479\n", + "487\n", + "491\n", + "499\n", + "503\n", + "509\n", + "521\n", + "523\n", + "541\n", + "547\n", + "557\n", + "563\n", + "569\n", + "571\n", + "577\n", + "587\n", + "593\n", + "599\n", + "601\n", + "607\n", + "613\n", + "617\n", + "619\n", + "631\n", + "641\n", + "643\n", + "647\n", + "653\n", + "659\n", + "661\n", + "673\n", + "677\n", + "683\n", + "691\n", + "701\n", + "709\n", + "719\n", + "727\n", + "733\n", + "739\n", + "743\n", + "751\n", + "757\n", + "761\n", + "769\n", + "773\n", + "787\n", + "797\n", + "809\n", + "811\n", + "821\n", + "823\n", + "827\n", + "829\n", + "839\n", + "853\n", + "857\n", + "859\n", + "863\n", + "877\n", + "881\n", + "883\n", + "887\n", + "907\n", + "911\n", + "919\n", + "929\n", + "937\n", + "941\n", + "947\n", + "953\n", + "967\n", + "971\n", + "977\n", + "983\n", + "991\n", + "997\n" + ] + } + ], "source": [ "# Print all the primes below 1000\n", "for prime in primes():\n", @@ -2261,9 +2436,9 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": { - "hideCode": true, + "hideCode": false, "hideOutput": false, "hidePrompt": false }, diff --git a/020-patterns/Solid Ideas.ipynb b/020-patterns/Solid Ideas.ipynb index db7b6af..a13d514 100644 --- a/020-patterns/Solid Ideas.ipynb +++ b/020-patterns/Solid Ideas.ipynb @@ -377,7 +377,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -387,7 +387,7 @@ "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0;34m...\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 11\u001b[0;31m \u001b[0mDolfin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0;34m...\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 11\u001b[0;31m \u001b[0mDolfin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;31mTypeError\u001b[0m: Can't instantiate abstract class Dolfin with abstract methods walk" ] } @@ -406,6 +406,39 @@ "Dolfin()" ] }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "ename": "NotImplementedError", + "evalue": "This animal cannot walk", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNotImplementedError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[0;34m...\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 11\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 12\u001b[0;31m \u001b[0mDolfin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwalk\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m\u001b[0m in \u001b[0;36mwalk\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mclass\u001b[0m \u001b[0mAnimal\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mwalk\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mNotImplementedError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"This animal cannot walk\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;32mclass\u001b[0m \u001b[0mMonkey\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mAnimal\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mNotImplementedError\u001b[0m: This animal cannot walk" + ] + } + ], + "source": [ + "class Animal:\n", + " def walk(self):\n", + " raise NotImplementedError(\"This animal cannot walk\")\n", + " \n", + "class Monkey(Animal):\n", + " def walk(self):\n", + " ...\n", + " \n", + "class Dolfin(Animal):\n", + " ...\n", + " \n", + "Dolfin().walk()" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -436,7 +469,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ @@ -459,7 +492,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ @@ -629,10 +662,105 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "['left-front',\n", + " 'left-middle-front',\n", + " 'left-middle-back',\n", + " 'left-back',\n", + " 'right-front',\n", + " 'right-middle-front',\n", + " 'right-middle-back',\n", + " 'right-back',\n", + " 'left-back',\n", + " 'right-back',\n", + " 'left-front',\n", + " 'right-front',\n", + " 'left-back',\n", + " 'right-back',\n", + " 'left-front',\n", + " 'right-front']" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "class Animal:\n", + " name = 'Unknown'\n", + " \n", + " # OCP: Even if our animal doesn't have legs, it will nonetheless have a legs\n", + " # list, if this constructor gets called. If users of the Animal class use this\n", + " # directly, they could get silent bugs by looking at e.g. dolphin.legs\n", + " def __init__(self):\n", + " self.legs = ['left-back', 'right-back', 'left-front', 'right-front']\n", + " \n", + " # ISP: not all animals have legs, why are we requiring them to have leg-names?\n", + " @abc.abstractmethod\n", + " def get_leg_names(self):\n", + " pass\n", + "\n", + "class Giraffe(Animal):\n", + " name = 'Giraffe'\n", + " \n", + " def get_leg_names(self):\n", + " return ', '.join(self.legs)\n", + " \n", + "class Tarantula(Animal):\n", + " name = 'Tarantula'\n", + " \n", + " def __init__(self):\n", + " self.legs = [\n", + " 'left-front', 'left-middle-front', 'left-middle-back', 'left-back',\n", + " 'right-front', 'right-middle-front', 'right-middle-back', 'right-back'\n", + " ]\n", + " \n", + " def get_leg_names(self):\n", + " return ', '.join(self.legs)\n", + "\n", + "class Butterfly(Animal):\n", + " name = 'Butterfly'\n", + " has_transformed = None\n", + " \n", + " # LSP: we are expecting this to initialize whether\n", + " # our butterfly is still a caterpillar or not, but that's\n", + " # not something that users of the superclass will do...\n", + " def set_is_transformed(self, transformed):\n", + " self.has_transformed = transformed\n", + " \n", + " def get_leg_names(self):\n", + " return ['leg {n}' for n in range(6 if self.has_transformed else 16)]\n", + "\n", + "class Zoo:\n", + " def __init__(self):\n", + " # DIP: bit of an extreme example, but rather than saying which animals\n", + " # are in our zoo, or passing a creator function, the constructor will\n", + " # only ever work exactly with these three animals.\n", + " self.animals = [\n", + " Tarantula(),\n", + " Butterfly(),\n", + " Giraffe()\n", + " ]\n", + " \n", + " # SRP: we are baking in how animals are shown to our domain model class\n", + " # (might also notice this links to separation of layers in DDD/MVC)\n", + " def print_animals():\n", + " for animal in self.animals:\n", + " print(f'A {animal.name} has {len(animal.get_leg_names())}')\n", + " \n", + "zoo = Zoo()\n", + "\n", + "# LOD: not only are we baking in the assumption that animals have legs,\n", + "# we're baking in the way that's stored - note that this has gone wrong for\n", + "# Butterflies who do not use the legs list\n", + "sum((zoo.animals[i].legs for i in range(3)), [])" + ] } ], "metadata": { From 79c484b114f63529df6b263e2fe5f10d708988b4 Mon Sep 17 00:00:00 2001 From: Phil Weir Date: Wed, 1 Jul 2020 08:25:31 +0000 Subject: [PATCH 6/6] magnum of opera notes --- 022-burette/A Magnum of Opera.ipynb | 1011 +++++++++++++++++++++++++++ 1 file changed, 1011 insertions(+) create mode 100644 022-burette/A Magnum of Opera.ipynb diff --git a/022-burette/A Magnum of Opera.ipynb b/022-burette/A Magnum of Opera.ipynb new file mode 100644 index 0000000..3523fb0 --- /dev/null +++ b/022-burette/A Magnum of Opera.ipynb @@ -0,0 +1,1011 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "hideCode": false, + "hidePrompt": false + }, + "source": [ + "# A Magnum of Opera (aka \"A Lot of Work\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "(or opuses, or opi, take your pick)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Previously, we focused on Flask and SQLAlchemy - we evolved from our Latency approach, better structuring our project, and leveraging tooling to do so in the Python ecosystem." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Rather than accelerating too quickly, I have kept most of the code the same as previously, but focused on a practical example of dependency injection. Firstly, to show how code can be decoupled, in this case with `injector`, and how that can give benefits to separation of concerns and those original DDD ideas of separated layers: domain, application and persistence." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Decorating the Lab" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "To demonstrate the power of decoupling - with or without an Inversion of Control container like `injector`'s - we will briefly rewrite the entire stack. Even more, we will switch to a completely different coding paradigm: coroutines. Our domain model and its tests will remain unchanged." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This requires one more Python construct that we have brushed over several times - `decorators`. Note that this is distinct from the _decorator pattern_ , which, in Python, links more to mixins and the wrapper pattern we looked at in previous weeks (reminder: `class MyDict: _real_dict = {}`)." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "How do decorators work? They take a function or method, and return a tweaked version. Perhaps this means a side-effect, such as recording an action, or a pure mutation, such as adjusting passed arguments or return values." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "They can be specified in a couple of ways:" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "class StringifyResult:\n", + " # Called when Python hits the decorator in code\n", + " def __init__(self, f):\n", + " self._f = f\n", + " \n", + " # Called when you call the function\n", + " def __call__(self, *args):\n", + " original_result = self._f(*args)\n", + " return str(original_result)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "@StringifyResult\n", + "def add_numbers(a, b):\n", + " return a + b" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'4'" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "add_numbers(1, 3)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "A more succint and common, but slightly less intuitive, way of writing this is as a function that returns a function:" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "def stringify_result(f):\n", + " # I've given args a and b for clarity, but *args, **kwargs\n", + " # is more common and flexible\n", + " def tweaked_f(a, b):\n", + " original_result = f(a, b)\n", + " return str(original_result)\n", + " \n", + " return tweaked_f" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "@stringify_result\n", + "def add_numbers(a, b):\n", + " return a + b" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'4'" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "add_numbers(1, 3)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We could do an entire session, or series of sessions, or [meetup series](https://twitter.com/belfastfp) on functional programming, but we'll suffice with a brief aside to whet the appetite." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Functional Works" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Functional programming can get very theoretical - there are excellent intros to the [computing theory](https://github.com/hmemcpy/milewski-ctfp-pdf) that give a whole new way about thinking about programming. For the moment:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "* functional programming focuses on functions, rather than objects\n", + "* state is local, not global or maintained - values are passed into functions, and returned from them\n", + "* functions can be passed all over the show\n", + "* it focuses on calling functions, nesting right down, rather than long sequences of commands (imperative programming)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In Python, we rarely take an exclusively functional approach, but venerable languages such as Haskell, Scala, Lisp, Clojure, (and dozens of new ones known only in fashionable coffee shops in Shoreditch) can be very or entirely functional." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "However, it's important to be aware of - it's the theoretical basis of MapReduce and massively scalable code. If state is not shared, globally or at a class/object level, parallelisation is trivial." + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'c': 4, 'a': 4, 'b': 8}" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "class Sequence:\n", + " content = 'abcbabbbcbabccba'\n", + " def count_distinct(self):\n", + " distinct = set(self.content)\n", + " return {character: self.content.count(character) for character in distinct}\n", + "\n", + "my_seq = Sequence()\n", + "my_seq.count_distinct()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "vs" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'c': 4, 'a': 4, 'b': 8}" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def count_distinct(content):\n", + " distinct = set(content)\n", + " return {character: content.count(character) for character in distinct}\n", + "\n", + "my_seq = 'abcbabbbcbabccba'\n", + "count_distinct(my_seq)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Why is the second helpful?" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "DISTINCTS: [{'c': 1, 'a': 1, 'b': 2}, {'a': 1, 'b': 3}, {'c': 1, 'a': 1, 'b': 2}, {'c': 2, 'a': 1, 'b': 1}]\n" + ] + }, + { + "data": { + "text/plain": [ + "{'c': 4, 'a': 4, 'b': 8}" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import textwrap\n", + "\n", + "def split_content_to_substrings(content):\n", + " return textwrap.fill(content, 4).split()\n", + "\n", + "def compose_distinct(distincts):\n", + " print('DISTINCTS:', list(distincts))\n", + " \n", + " # Work out all occurring characters\n", + " all_characters = set(sum([list(d.keys()) for d in distincts], []))\n", + " \n", + " counts = {c: 0 for c in all_characters}\n", + " # Less functional - this could be map/comprehension, but easier to read!\n", + " for distinct in distincts:\n", + " for c, ct in distinct.items():\n", + " counts[c] += ct\n", + " \n", + " return counts\n", + "\n", + "# a series of composed functions\n", + "compose_distinct(list(map(count_distinct, split_content_to_substrings(my_seq))))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Unlike the first, this could be immediately parallelized." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### More Painting" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Many decorators exist:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "* `@classmethod`: indicates a class method (first arg is the class, not `self`)\n", + "* `@staticmethod`: indicates a class method (no first arg)\n", + "* `@timeit`: indicates you want this function timed (recall timeit from the Latency exercises)\n", + "* `@contextmanager`: preps a function for use in a with statement\n", + "* `@property`: indicates that you want to expose a getter&/setter as an object property\n", + "* `@pytest.fixture`: indicates that the function it applies to defined an injectable fixture\n", + "* `@app.route`: indicates that the following function is a route-handler in Flask" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Note from the last one, that decorators can be written as object methods, as well as functions." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Coroutines" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Coroutines in Python started out as decorators - @asyncio.coroutine - but this approach is now deprecated and you will generally see the syntax:" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [], + "source": [ + "async def my_asynchronous_function(a, b):\n", + " return a + b" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This should look like any other function, except the `async`. And, in fact, it really is - except that:" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "my_asynchronous_function(1, 2)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "It returns a coroutine. This is a construct that can be scheduled, and may have a result, but not immediately. They can be chained. Again, we'll look at practical examples rather than delving into coroutine theory. However, coroutines work on the principle of an event loop that ensures they actually happen." + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import asyncio\n", + "\n", + "# This approach is required if no event loop yet exists - but in Jupyter it does\n", + "# asyncio.run(my_asynchronous_function)\n", + "\n", + "await my_asynchronous_function(1, 2)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The `await` syntax allows us to compose these like ordinary functions - but if some IO, sleep or such is taking time, Python can carry on executing other coroutines that have been scheduled, and switch between them, returning control to the first one when it's blocking step is done." + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Doing\n", + "3\n", + "Done\n" + ] + } + ], + "source": [ + "async def my_slow_function():\n", + " print('Doing')\n", + " await asyncio.sleep(3)\n", + " print('Done')\n", + " \n", + "loop = asyncio.get_event_loop()\n", + "result = loop.create_task(my_slow_function())\n", + "\n", + "await asyncio.sleep(1)\n", + "other_result = await my_asynchronous_function(1, 2)\n", + "print(other_result)\n", + "await result" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "An example of where this is useful occurs in HTTP responses..." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Opera on Tour" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We have explored the Magnum Opus server in a number of different ways, and seen how we can separate business logic from our application." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Our main exercise will be to work through the new code, and to adapt it for a new type of database." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Raising the roof" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "First a few extra dependencies:" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "hideCode": false, + "hidePrompt": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Requirement already satisfied: findspark in /opt/conda/lib/python3.7/site-packages (1.4.2)\n", + "Requirement already satisfied: cassandra-driver in /opt/conda/lib/python3.7/site-packages (3.24.0)\n", + "Requirement already satisfied: flask-cqlalchemy in /opt/conda/lib/python3.7/site-packages (1.2.0)\n", + "Collecting flask\n", + " Downloading Flask-1.1.2-py2.py3-none-any.whl (94 kB)\n", + "\u001b[K |████████████████████████████████| 94 kB 2.7 MB/s eta 0:00:011\n", + "\u001b[?25hRequirement already satisfied: geomet<0.3,>=0.1 in /opt/conda/lib/python3.7/site-packages (from cassandra-driver) (0.2.1.post1)\n", + "Requirement already satisfied: six>=1.9 in /opt/conda/lib/python3.7/site-packages (from cassandra-driver) (1.15.0)\n", + "Requirement already satisfied: blist in /opt/conda/lib/python3.7/site-packages (from flask-cqlalchemy) (1.3.6)\n", + "Collecting itsdangerous>=0.24\n", + " Downloading itsdangerous-1.1.0-py2.py3-none-any.whl (16 kB)\n", + "Requirement already satisfied: Jinja2>=2.10.1 in /opt/conda/lib/python3.7/site-packages (from flask) (2.11.2)\n", + "Requirement already satisfied: click>=5.1 in /opt/conda/lib/python3.7/site-packages (from flask) (7.1.2)\n", + "Collecting Werkzeug>=0.15\n", + " Downloading Werkzeug-1.0.1-py2.py3-none-any.whl (298 kB)\n", + "\u001b[K |████████████████████████████████| 298 kB 7.3 MB/s eta 0:00:01\n", + "\u001b[?25hRequirement already satisfied: MarkupSafe>=0.23 in /opt/conda/lib/python3.7/site-packages (from Jinja2>=2.10.1->flask) (1.1.1)\n", + "Installing collected packages: itsdangerous, Werkzeug, flask\n", + "Successfully installed Werkzeug-1.0.1 flask-1.1.2 itsdangerous-1.1.0\n" + ] + } + ], + "source": [ + "!pip3 install findspark cassandra-driver flask-cqlalchemy flask" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "hideCode": false, + "hidePrompt": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " % Total % Received % Xferd Average Speed Time Time Time Current\n", + " Dload Upload Total Spent Left Speed\n", + " 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\n", + "100 8340k 100 8340k 0 0 4398k 0 0:00:01 0:00:01 --:--:-- 7385k\n" + ] + } + ], + "source": [ + "!curl -L -O http://dl.bintray.com/spark-packages/maven/datastax/spark-cassandra-connector/2.4.0-s_2.11/spark-cassandra-connector-2.4.0-s_2.11.jar" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Cassandra is a highly scalable NoSQL database - we have one conveniently set up." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "hideCode": false, + "hidePrompt": false + }, + "outputs": [], + "source": [ + "CASSANDRA_PASSWORD = \"Le2V2gZ0nk\"" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "hideCode": false, + "hidePrompt": false + }, + "outputs": [], + "source": [ + "import os\n", + "import findspark\n", + "\n", + "os.environ['JAVA_HOME'] = '/usr/lib/jvm/java-8-openjdk-amd64'\n", + "os.environ['CQLENG_ALLOW_SCHEMA_MANAGEMENT'] = '1'\n", + "os.environ['PYSPARK_SUBMIT_ARGS'] = '--packages com.datastax.spark:spark-cassandra-connector_2.11:2.4.2 --conf spark.cassandra.connection.host=cassandra-0 pyspark-shell'\n", + "findspark.init()\n", + "\n", + "import pyspark" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "hideCode": false, + "hidePrompt": false + }, + "outputs": [], + "source": [ + "conf = pyspark.SparkConf()\n", + " \n", + "conf.set(\"spark.jars\", \"./spark-cassandra-connector-2.4.0-s_2.11.jar\") # spark-cassandra-connect jar\n", + " \n", + "conf.set(\"spark.cassandra.connection.host\", \"cassandra\")\n", + "conf.set(\"spark.cassandra.auth.username\", \"cassandra\")\n", + "conf.set(\"spark.cassandra.auth.password\", CASSANDRA_PASSWORD)\n", + "\n", + "\n", + "sc = pyspark.SparkContext(conf=conf)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "I don't generally use standard examples, as you'll see them anyway, but this is particularly nice example of how stats and parallelism can let you calculate `pi`:" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": { + "hideCode": false, + "hidePrompt": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3.14152816\n" + ] + } + ], + "source": [ + "import random\n", + "\n", + "num_samples = 100000000\n", + "\n", + "def inside(p): \n", + " x, y = random.random(), random.random()\n", + " return x*x + y*y < 1\n", + "\n", + "count = sc.parallelize(range(0, num_samples)).filter(inside).count()\n", + "pi = 4 * count / num_samples\n", + "print(pi)\n", + "sc.stop()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We can use spark to handle our data that has been inserted into Cassandra." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "hideCode": false, + "hidePrompt": false + }, + "outputs": [], + "source": [ + "from pyspark.sql import SQLContext\n", + "sql_context = SQLContext(sc)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "hideCode": false, + "hidePrompt": false + }, + "outputs": [], + "source": [ + "table_df = sql_context.read\\\n", + " .format(\"org.apache.spark.sql.cassandra\")\\\n", + " .options(table='substance', keyspace='pythoncourse')\\\n", + " .load()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### A few hints" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Helpfully, someone created the `flask_cqlalchemy` module to make it easier (not trivial) to use SQLAlchemy style code with Cassandra." + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "hideCode": false, + "hidePrompt": false + }, + "outputs": [], + "source": [ + "from cassandra.auth import PlainTextAuthProvider" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "hideCode": false, + "hidePrompt": false + }, + "outputs": [], + "source": [ + "import uuid\n", + "from flask import Flask\n", + "from flask_cqlalchemy import CQLAlchemy\n", + "\n", + "app = Flask(__name__)\n", + "app.config['CASSANDRA_HOSTS'] = ['cassandra']\n", + "app.config['CASSANDRA_KEYSPACE'] = \"pythoncourse\"\n", + "app.config['CASSANDRA_SETUP_KWARGS'] = {'protocol_version': 3, \"auth_provider\": PlainTextAuthProvider(\n", + " username='cassandra', password=CASSANDRA_PASSWORD)}\n", + "db = CQLAlchemy(app)\n", + "\n", + "\n", + "class Substance(db.Model):\n", + " id = db.columns.UUID(primary_key=True, default=uuid.uuid4)\n", + " nature = db.columns.Text()\n", + " state = db.columns.List(db.columns.Text())" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "hideCode": false, + "hidePrompt": false + }, + "outputs": [], + "source": [ + "#db.sync_db()" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": { + "hideCode": false, + "hidePrompt": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "522b6440-bdee-4d82-b531-030edb4248a3 Sulphur\n", + "4d76c633-26bb-4ed8-be44-558440d5d7e5 Sulphur\n", + "b6d2e363-30a8-4e5e-92a3-8c7c8391b060 Sulphur\n", + "f7598b0a-1050-4a5e-96be-7785bd8b2f27 Sulphur\n", + "1f1a941b-019a-4f4f-acfd-09968f6e9d03 Sulphur\n", + "a227e5fc-6b81-4a54-a421-183a361368d1 Sulphur\n" + ] + } + ], + "source": [ + "for substance in Substance.objects().all():\n", + " print(substance.id, substance.nature)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "What can we do with this? Looking back at our earlier work on counting distinct perhaps..." + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": { + "hideCode": false, + "hidePrompt": false + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
naturecount
0Sulphur6
\n", + "
" + ], + "text/plain": [ + " nature count\n", + "0 Sulphur 6" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "table_df.groupby('nature').count().toPandas()" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
distinct_natures
01
\n", + "
" + ], + "text/plain": [ + " distinct_natures\n", + "0 1" + ] + }, + "execution_count": 38, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from pyspark.sql.functions import approx_count_distinct, countDistinct\n", + "nature_counts = table_df.agg(approx_count_distinct(table_df.nature).alias('distinct_natures')).collect()\n", + "sql_context.createDataFrame(nature_counts).toPandas()" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
distinct_natures
01
\n", + "
" + ], + "text/plain": [ + " distinct_natures\n", + "0 1" + ] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "nature_counts = table_df.agg(approx_count_distinct(table_df.nature).alias('distinct_natures')).collect()\n", + "sql_context.createDataFrame(nature_counts).toPandas()" + ] + } + ], + "metadata": { + "hide_code_all_hidden": false, + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.6" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +}