{"id":9209,"date":"2022-12-22T18:48:08","date_gmt":"2022-12-22T18:48:08","guid":{"rendered":"https:\/\/www.blopig.com\/blog\/?p=9209"},"modified":"2022-12-22T18:48:10","modified_gmt":"2022-12-22T18:48:10","slug":"quality-stats","status":"publish","type":"post","link":"https:\/\/www.blopig.com\/blog\/2022\/12\/quality-stats\/","title":{"rendered":"Quality Stats"},"content":{"rendered":"\n<p><em>Disclaimer &#8211; the title is a Quality Street pun only and bears no relation to the quality of the data or analysis presented below. This whole blog post is basically to discredit the personal chocolate preferences of a group member who shall remain nameless. Safe to say though, they Vostly overestimated people&#8217;s love for the Toffee Finger. Long live the Orange Creme.<\/em><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2022\/12\/image-27.png?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"625\" height=\"366\" loading=\"lazy\" src=\"https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2022\/12\/image-27.png?resize=625%2C366&#038;ssl=1\" alt=\"\" class=\"wp-image-9231\" srcset=\"https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2022\/12\/image-27.png?w=803&amp;ssl=1 803w, https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2022\/12\/image-27.png?resize=300%2C176&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2022\/12\/image-27.png?resize=768%2C450&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2022\/12\/image-27.png?resize=624%2C365&amp;ssl=1 624w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/a><\/figure>\n\n\n\n<!--more-->\n\n\n\n<p>In the run-up to Christmas, I was arguing with another member of the group about which are the best and worst Quality Street chocolates. This is clearly an important topic, with <a href=\"https:\/\/twitter.com\/yougov\/status\/940868550700527616?lang=en-GB\" target=\"_blank\" rel=\"noreferrer noopener\">YouGov<\/a> previously dedicating vast resources (I assume) attempting to answer this very question.<\/p>\n\n\n\n<p>However, as the YouGov poll did not perfectly align with my personal and very accurate preferences, I decided to run another, better experiment. For this experiment, I bought a tub of Quality Street, counted all the chocolates, and then left the tub out in the common area for hungry opiglets to consume. I then recounted the chocolates at various points over the next two days to find out which flavours disappeared first, and perhaps more importantly, which sad chocolates were taken only after all other options were exhausted.<\/p>\n\n\n\n<p>As expected, crowd favourites The Purple One and The Green Triangle were quick to go, along with the Fudge and Milk Choc Block. The cremes, controversially my personal favourites, sadly performed only averagely. However, to my great delight, the Toffee Finger comprehensively beat all other competition (including the Coconut Eclair!) to take the wooden spoon and provide me with a moderate degree of smugness in the end.<\/p>\n\n\n\n<p>In an attempt to make this blog post somewhat useful, I&#8217;ve included the code I used to make the results plot below. This code should allow you to sort a DataFrame using a custom list, pivot the data when you&#8217;re an idiot and type it up the wrong way round, and make a DIY colour palette for your plots.<\/p>\n\n\n\n<p>And remember, even though you may be appalled by others&#8217; chocolate preferences, this actually makes them the perfect person to sit down and share a box with during these festive times.<\/p>\n\n\n\n<p>Happy holidays!<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import os\nimport pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"Read-in-data\">Read in data<a href=\"#Read-in-data\">\u00b6<\/a><\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\"># data I manually recorded in a csv\nquality_df = pd.read_csv(\"Quality_data.csv\", names=[\"flavour\", \"t1\", \"t2\", \"t3\", \"t4\", \"t5\", \"t6\", \"t7\", \"t8\", \"t9\"])\n\n# YouGov ranking - https:\/\/twitter.com\/yougov\/status\/940868550700527616?lang=en-GB\nyougov_ranking = [\"The Purple One\", \"The Green Triangle\", \"Caramel Swirl\", \"Strawberry Delight\", \"Orange Creme\", \"Milk Choc Block\", \"Fudge\", \"Toffee Finger\", \"Orange Chocolate Crunch\", \"Toffee Penny\", \"Coconut Eclair\"]\n\n# sort data (reverse so that plot is in sensible order later)\nquality_df[\"flavour\"] = quality_df[\"flavour\"].astype(\"category\")\nquality_df[\"flavour\"] = quality_df[\"flavour\"].cat.set_categories(yougov_ranking)\nquality_df = quality_df.sort_values([\"flavour\"], ascending=False).reset_index(drop=True)\n\nquality_df<\/pre>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th><\/th><th>flavour<\/th><th>t1<\/th><th>t2<\/th><th>t3<\/th><th>t4<\/th><th>t5<\/th><th>t6<\/th><th>t7<\/th><th>t8<\/th><th>t9<\/th><\/tr><\/thead><tbody><tr><th>0<\/th><td>Coconut Eclair<\/td><td>5<\/td><td>5<\/td><td>5<\/td><td>2<\/td><td>2<\/td><td>2<\/td><td>2<\/td><td>2<\/td><td>0<\/td><\/tr><tr><th>1<\/th><td>Toffee Penny<\/td><td>6<\/td><td>6<\/td><td>6<\/td><td>3<\/td><td>3<\/td><td>1<\/td><td>1<\/td><td>1<\/td><td>0<\/td><\/tr><tr><th>2<\/th><td>Orange Chocolate Crunch<\/td><td>5<\/td><td>5<\/td><td>5<\/td><td>5<\/td><td>4<\/td><td>2<\/td><td>1<\/td><td>0<\/td><td>0<\/td><\/tr><tr><th>3<\/th><td>Toffee Finger<\/td><td>7<\/td><td>6<\/td><td>6<\/td><td>5<\/td><td>5<\/td><td>5<\/td><td>5<\/td><td>4<\/td><td>2<\/td><\/tr><tr><th>4<\/th><td>Fudge<\/td><td>8<\/td><td>6<\/td><td>4<\/td><td>0<\/td><td>0<\/td><td>0<\/td><td>0<\/td><td>0<\/td><td>0<\/td><\/tr><tr><th>5<\/th><td>Milk Choc Block<\/td><td>4<\/td><td>3<\/td><td>1<\/td><td>0<\/td><td>0<\/td><td>0<\/td><td>0<\/td><td>0<\/td><td>0<\/td><\/tr><tr><th>6<\/th><td>Orange Creme<\/td><td>6<\/td><td>6<\/td><td>6<\/td><td>3<\/td><td>3<\/td><td>2<\/td><td>2<\/td><td>0<\/td><td>0<\/td><\/tr><tr><th>7<\/th><td>Strawberry Delight<\/td><td>7<\/td><td>5<\/td><td>5<\/td><td>3<\/td><td>2<\/td><td>0<\/td><td>0<\/td><td>0<\/td><td>0<\/td><\/tr><tr><th>8<\/th><td>Caramel Swirl<\/td><td>7<\/td><td>7<\/td><td>5<\/td><td>2<\/td><td>1<\/td><td>1<\/td><td>1<\/td><td>1<\/td><td>1<\/td><\/tr><tr><th>9<\/th><td>The Green Triangle<\/td><td>4<\/td><td>4<\/td><td>3<\/td><td>1<\/td><td>0<\/td><td>0<\/td><td>0<\/td><td>0<\/td><td>0<\/td><\/tr><tr><th>10<\/th><td>The Purple One<\/td><td>5<\/td><td>4<\/td><td>4<\/td><td>0<\/td><td>0<\/td><td>0<\/td><td>0<\/td><td>0<\/td><td>0<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"Pivot-data-for-plotting\">Pivot data for plotting<a href=\"#Pivot-data-for-plotting\">\u00b6<\/a><\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">quality_df = quality_df.T\n\nnew_header = quality_df.iloc[0]   # grab the first row for the header\nquality_df = quality_df[1:]       # take the data less the header row\nquality_df.columns = new_header   # set the header row as the df header\n\nquality_df = quality_df.reset_index(drop=True)\nquality_df.index.names = [\"time\"]\nquality_df<\/pre>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>flavour<\/th><th>Coconut Eclair<\/th><th>Toffee Penny<\/th><th>Orange Chocolate Crunch<\/th><th>Toffee Finger<\/th><th>Fudge<\/th><th>Milk Choc Block<\/th><th>Orange Creme<\/th><th>Strawberry Delight<\/th><th>Caramel Swirl<\/th><th>The Green Triangle<\/th><th>The Purple One<\/th><\/tr><tr><th>time<\/th><th><\/th><th><\/th><th><\/th><th><\/th><th><\/th><th><\/th><th><\/th><th><\/th><th><\/th><th><\/th><th><\/th><\/tr><\/thead><tbody><tr><th>0<\/th><td>5<\/td><td>6<\/td><td>5<\/td><td>7<\/td><td>8<\/td><td>4<\/td><td>6<\/td><td>7<\/td><td>7<\/td><td>4<\/td><td>5<\/td><\/tr><tr><th>1<\/th><td>5<\/td><td>6<\/td><td>5<\/td><td>6<\/td><td>6<\/td><td>3<\/td><td>6<\/td><td>5<\/td><td>7<\/td><td>4<\/td><td>4<\/td><\/tr><tr><th>2<\/th><td>5<\/td><td>6<\/td><td>5<\/td><td>6<\/td><td>4<\/td><td>1<\/td><td>6<\/td><td>5<\/td><td>5<\/td><td>3<\/td><td>4<\/td><\/tr><tr><th>3<\/th><td>2<\/td><td>3<\/td><td>5<\/td><td>5<\/td><td>0<\/td><td>0<\/td><td>3<\/td><td>3<\/td><td>2<\/td><td>1<\/td><td>0<\/td><\/tr><tr><th>4<\/th><td>2<\/td><td>3<\/td><td>4<\/td><td>5<\/td><td>0<\/td><td>0<\/td><td>3<\/td><td>2<\/td><td>1<\/td><td>0<\/td><td>0<\/td><\/tr><tr><th>5<\/th><td>2<\/td><td>1<\/td><td>2<\/td><td>5<\/td><td>0<\/td><td>0<\/td><td>2<\/td><td>0<\/td><td>1<\/td><td>0<\/td><td>0<\/td><\/tr><tr><th>6<\/th><td>2<\/td><td>1<\/td><td>1<\/td><td>5<\/td><td>0<\/td><td>0<\/td><td>2<\/td><td>0<\/td><td>1<\/td><td>0<\/td><td>0<\/td><\/tr><tr><th>7<\/th><td>2<\/td><td>1<\/td><td>0<\/td><td>4<\/td><td>0<\/td><td>0<\/td><td>0<\/td><td>0<\/td><td>1<\/td><td>0<\/td><td>0<\/td><\/tr><tr><th>8<\/th><td>0<\/td><td>0<\/td><td>0<\/td><td>2<\/td><td>0<\/td><td>0<\/td><td>0<\/td><td>0<\/td><td>1<\/td><td>0<\/td><td>0<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"Plot-data\">Plot data<a href=\"#Plot-data\">\u00b6<\/a><\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">flavours = quality_df.columns.tolist()\ntime = quality_df.index.tolist()\n\ndata = [quality_df[flavour].tolist() for flavour in flavours]\nnormalised_data = np.zeros_like(data).astype(float)\nfor i in range(len(time)):\n    normalised_data[:,i] = (np.array(data)[:,i]) \/ np.array(data)[:,i].sum()<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">flavour_to_colour = {\"The Purple One\":          \"purple\",\n                     \"The Green Triangle\":      \"limegreen\",\n                     \"Caramel Swirl\":           \"gold\",\n                     \"Strawberry Delight\":      \"red\",\n                     \"Orange Creme\":            \"darkorange\",\n                     \"Milk Choc Block\":         \"darkgreen\",\n                     \"Fudge\":                   \"fuchsia\",\n                     \"Toffee Finger\":           \"chocolate\",\n                     \"Orange Chocolate Crunch\": \"orangered\",\n                     \"Toffee Penny\":            \"goldenrod\",\n                     \"Coconut Eclair\":          \"mediumblue\"}\n\npalette = [colour for colour in flavour_to_colour.values()]\npalette.reverse()<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"># stacked area plot\nplt.stackplot(time, normalised_data, labels=flavours, colors=palette)\n\nplt.legend(reversed(plt.legend().legendHandles), reversed(flavours), bbox_to_anchor=(1.04, 1), loc=\"upper left\")\n\nplt.xlim([time[0], time[-1]])\nplt.ylim([0,1])\nplt.xlabel(\"Random times I checked the tub\")\nplt.title(\"Quality Street tub composition over time\\n(chocolates ordered according to YouGov ranking)\")\nplt.show()<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2022\/12\/image-27.png?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"625\" height=\"366\" loading=\"lazy\" src=\"https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2022\/12\/image-27.png?resize=625%2C366&#038;ssl=1\" alt=\"\" class=\"wp-image-9231\" srcset=\"https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2022\/12\/image-27.png?w=803&amp;ssl=1 803w, https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2022\/12\/image-27.png?resize=300%2C176&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2022\/12\/image-27.png?resize=768%2C450&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2022\/12\/image-27.png?resize=624%2C365&amp;ssl=1 624w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/a><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Disclaimer &#8211; the title is a Quality Street pun only and bears no relation to the quality of the data or analysis presented below. This whole blog post is basically to discredit the personal chocolate preferences of a group member who shall remain nameless. Safe to say though, they Vostly overestimated people&#8217;s love for the [&hellip;]<\/p>\n","protected":false},"author":91,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","wikipediapreview_detectlinks":true,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"ngg_post_thumbnail":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[621,46],"tags":[],"ppma_author":[558],"class_list":["post-9209","post","type-post","status-publish","format-standard","hentry","category-data-visualization","category-humour"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"authors":[{"term_id":558,"user_id":91,"is_guest":0,"slug":"lewis","display_name":"Lewis Chinery","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/29bddf38b6dd9db3c7161683ddd1a5fc6bad04b6f40e83334e5d43972380ed54?s=96&d=mm&r=g","0":null,"1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":""}],"_links":{"self":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/9209","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/users\/91"}],"replies":[{"embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/comments?post=9209"}],"version-history":[{"count":5,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/9209\/revisions"}],"predecessor-version":[{"id":9237,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/9209\/revisions\/9237"}],"wp:attachment":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/media?parent=9209"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/categories?post=9209"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/tags?post=9209"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=9209"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}