{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "name": "hivemind1.ipynb", "provenance": [], "collapsed_sections": [], "toc_visible": true, "authorship_tag": "ABX9TyPDIxFOaQ6ugsOYXbj0e6It", "include_colab_link": true }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "f24a2c9e820b4249ab63654b9ef56604": { "model_module": "@jupyter-widgets/controls", "model_name": "HBoxModel", "state": { "_view_name": "HBoxView", "_dom_classes": [], "_model_name": "HBoxModel", "_view_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_view_count": null, "_view_module_version": "1.5.0", "box_style": "", "layout": "IPY_MODEL_e4dc73cf71714fd38dd09fd06a8608c7", "_model_module": "@jupyter-widgets/controls", "children": [ "IPY_MODEL_652720149f1843cd964a3fae5a32b6d7", "IPY_MODEL_a5b643a5d4db43769c04ded49d2ba09e" ] } }, "e4dc73cf71714fd38dd09fd06a8608c7": { "model_module": "@jupyter-widgets/base", "model_name": "LayoutModel", "state": { "_view_name": "LayoutView", "grid_template_rows": null, "right": null, "justify_content": null, "_view_module": "@jupyter-widgets/base", "overflow": null, "_model_module_version": "1.2.0", "_view_count": null, "flex_flow": null, "width": null, "min_width": null, "border": null, "align_items": null, "bottom": null, "_model_module": "@jupyter-widgets/base", "top": null, "grid_column": null, "overflow_y": null, "overflow_x": null, "grid_auto_flow": null, "grid_area": null, "grid_template_columns": null, "flex": null, "_model_name": "LayoutModel", "justify_items": null, "grid_row": null, "max_height": null, "align_content": null, "visibility": null, "align_self": null, "height": null, "min_height": null, "padding": null, "grid_auto_rows": null, "grid_gap": null, "max_width": null, "order": null, "_view_module_version": "1.2.0", "grid_template_areas": null, "object_position": null, "object_fit": null, "grid_auto_columns": null, "margin": null, "display": null, "left": null } }, "652720149f1843cd964a3fae5a32b6d7": { "model_module": "@jupyter-widgets/controls", "model_name": "FloatProgressModel", "state": { "_view_name": "ProgressView", "style": "IPY_MODEL_2859a8220b6340fcba1862b35fbe5b91", "_dom_classes": [], "description": "UCF101TrainTestSplits-RecognitionTask.zip: 100%", "_model_name": "FloatProgressModel", "bar_style": "success", "max": 113943, "_view_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "value": 113943, "_view_count": null, "_view_module_version": "1.5.0", "orientation": "horizontal", "min": 0, "description_tooltip": null, "_model_module": "@jupyter-widgets/controls", "layout": "IPY_MODEL_cfa563330e4b45cd9a4197bdf9ec6757" } }, "a5b643a5d4db43769c04ded49d2ba09e": { "model_module": "@jupyter-widgets/controls", "model_name": "HTMLModel", "state": { "_view_name": "HTMLView", "style": "IPY_MODEL_838f5f7533314ade8fa3859ef7f46bf1", "_dom_classes": [], "description": "", "_model_name": "HTMLModel", "placeholder": "​", "_view_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "value": " 111k/111k [00:00<00:00, 1.49MB/s]", "_view_count": null, "_view_module_version": "1.5.0", "description_tooltip": null, "_model_module": "@jupyter-widgets/controls", "layout": "IPY_MODEL_6a30b268827f42e78da55a27979ddf47" } }, "2859a8220b6340fcba1862b35fbe5b91": { "model_module": "@jupyter-widgets/controls", "model_name": "ProgressStyleModel", "state": { "_view_name": "StyleView", "_model_name": "ProgressStyleModel", "description_width": "initial", "_view_module": "@jupyter-widgets/base", "_model_module_version": "1.5.0", "_view_count": null, "_view_module_version": "1.2.0", "bar_color": null, "_model_module": "@jupyter-widgets/controls" } }, "cfa563330e4b45cd9a4197bdf9ec6757": { "model_module": "@jupyter-widgets/base", "model_name": "LayoutModel", "state": { "_view_name": "LayoutView", "grid_template_rows": null, "right": null, "justify_content": null, "_view_module": "@jupyter-widgets/base", "overflow": null, "_model_module_version": "1.2.0", "_view_count": null, "flex_flow": null, "width": null, "min_width": null, "border": null, "align_items": null, "bottom": null, "_model_module": "@jupyter-widgets/base", "top": null, "grid_column": null, "overflow_y": null, "overflow_x": null, "grid_auto_flow": null, "grid_area": null, "grid_template_columns": null, "flex": null, "_model_name": "LayoutModel", "justify_items": null, "grid_row": null, "max_height": null, "align_content": null, "visibility": null, "align_self": null, "height": null, "min_height": null, "padding": null, "grid_auto_rows": null, "grid_gap": null, "max_width": null, "order": null, "_view_module_version": "1.2.0", "grid_template_areas": null, "object_position": null, "object_fit": null, "grid_auto_columns": null, "margin": null, "display": null, "left": null } }, "838f5f7533314ade8fa3859ef7f46bf1": { "model_module": "@jupyter-widgets/controls", "model_name": "DescriptionStyleModel", "state": { "_view_name": "StyleView", "_model_name": "DescriptionStyleModel", "description_width": "", "_view_module": "@jupyter-widgets/base", "_model_module_version": "1.5.0", "_view_count": null, "_view_module_version": "1.2.0", "_model_module": "@jupyter-widgets/controls" } }, "6a30b268827f42e78da55a27979ddf47": { "model_module": "@jupyter-widgets/base", "model_name": "LayoutModel", "state": { "_view_name": "LayoutView", "grid_template_rows": null, "right": null, "justify_content": null, "_view_module": "@jupyter-widgets/base", "overflow": null, "_model_module_version": "1.2.0", "_view_count": null, "flex_flow": null, "width": null, "min_width": null, "border": null, "align_items": null, "bottom": null, "_model_module": "@jupyter-widgets/base", "top": null, "grid_column": null, "overflow_y": null, "overflow_x": null, "grid_auto_flow": null, "grid_area": null, "grid_template_columns": null, "flex": null, "_model_name": "LayoutModel", "justify_items": null, "grid_row": null, "max_height": null, "align_content": null, "visibility": null, "align_self": null, "height": null, "min_height": null, "padding": null, "grid_auto_rows": null, "grid_gap": null, "max_width": null, "order": null, "_view_module_version": "1.2.0", "grid_template_areas": null, "object_position": null, "object_fit": null, "grid_auto_columns": null, "margin": null, "display": null, "left": null } }, "d15b4d02e1d84ce9b218dde279f11c59": { "model_module": "@jupyter-widgets/controls", "model_name": "HBoxModel", "state": { "_view_name": "HBoxView", "_dom_classes": [], "_model_name": "HBoxModel", "_view_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_view_count": null, "_view_module_version": "1.5.0", "box_style": "", "layout": "IPY_MODEL_446c92b5b92845249477c60af3f63faf", "_model_module": "@jupyter-widgets/controls", "children": [ "IPY_MODEL_d63d7a10beab42179bcd6b4f5a433a49", "IPY_MODEL_771d95358ad64e9c8742e416e61261da" ] } }, "446c92b5b92845249477c60af3f63faf": { "model_module": "@jupyter-widgets/base", "model_name": "LayoutModel", "state": { "_view_name": "LayoutView", "grid_template_rows": null, "right": null, "justify_content": null, "_view_module": "@jupyter-widgets/base", "overflow": null, "_model_module_version": "1.2.0", "_view_count": null, "flex_flow": null, "width": null, "min_width": null, "border": null, "align_items": null, "bottom": null, "_model_module": "@jupyter-widgets/base", "top": null, "grid_column": null, "overflow_y": null, "overflow_x": null, "grid_auto_flow": null, "grid_area": null, "grid_template_columns": null, "flex": null, "_model_name": "LayoutModel", "justify_items": null, "grid_row": null, "max_height": null, "align_content": null, "visibility": null, "align_self": null, "height": null, "min_height": null, "padding": null, "grid_auto_rows": null, "grid_gap": null, "max_width": null, "order": null, "_view_module_version": "1.2.0", "grid_template_areas": null, "object_position": null, "object_fit": null, "grid_auto_columns": null, "margin": null, "display": null, "left": null } }, "d63d7a10beab42179bcd6b4f5a433a49": { "model_module": "@jupyter-widgets/controls", "model_name": "FloatProgressModel", "state": { "_view_name": "ProgressView", "style": "IPY_MODEL_767d69f1b35e4df8bb4e718772c02b20", "_dom_classes": [], "description": "UCF101.rar: 100%", "_model_name": "FloatProgressModel", "bar_style": "success", "max": 6932971618, "_view_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "value": 6932971618, "_view_count": null, "_view_module_version": "1.5.0", "orientation": "horizontal", "min": 0, "description_tooltip": null, "_model_module": "@jupyter-widgets/controls", "layout": "IPY_MODEL_8741b1c90f514abc950d3cdf4d63b5bf" } }, "771d95358ad64e9c8742e416e61261da": { "model_module": "@jupyter-widgets/controls", "model_name": "HTMLModel", "state": { "_view_name": "HTMLView", "style": "IPY_MODEL_52f2278bb6f04526a08a75db50680708", "_dom_classes": [], "description": "", "_model_name": "HTMLModel", "placeholder": "​", "_view_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "value": " 6.46G/6.46G [01:59<00:00, 57.8MB/s]", "_view_count": null, "_view_module_version": "1.5.0", "description_tooltip": null, "_model_module": "@jupyter-widgets/controls", "layout": "IPY_MODEL_15696888463a4d668d7ff7e4f5c93ee3" } }, "767d69f1b35e4df8bb4e718772c02b20": { "model_module": "@jupyter-widgets/controls", "model_name": "ProgressStyleModel", "state": { "_view_name": "StyleView", "_model_name": "ProgressStyleModel", "description_width": "initial", "_view_module": "@jupyter-widgets/base", "_model_module_version": "1.5.0", "_view_count": null, "_view_module_version": "1.2.0", "bar_color": null, "_model_module": "@jupyter-widgets/controls" } }, "8741b1c90f514abc950d3cdf4d63b5bf": { "model_module": "@jupyter-widgets/base", "model_name": "LayoutModel", "state": { "_view_name": "LayoutView", "grid_template_rows": null, "right": null, "justify_content": null, "_view_module": "@jupyter-widgets/base", "overflow": null, "_model_module_version": "1.2.0", "_view_count": null, "flex_flow": null, "width": null, "min_width": null, "border": null, "align_items": null, "bottom": null, "_model_module": "@jupyter-widgets/base", "top": null, "grid_column": null, "overflow_y": null, "overflow_x": null, "grid_auto_flow": null, "grid_area": null, "grid_template_columns": null, "flex": null, "_model_name": "LayoutModel", "justify_items": null, "grid_row": null, "max_height": null, "align_content": null, "visibility": null, "align_self": null, "height": null, "min_height": null, "padding": null, "grid_auto_rows": null, "grid_gap": null, "max_width": null, "order": null, "_view_module_version": "1.2.0", "grid_template_areas": null, "object_position": null, "object_fit": null, "grid_auto_columns": null, "margin": null, "display": null, "left": null } }, "52f2278bb6f04526a08a75db50680708": { "model_module": "@jupyter-widgets/controls", "model_name": "DescriptionStyleModel", "state": { "_view_name": "StyleView", "_model_name": "DescriptionStyleModel", "description_width": "", "_view_module": "@jupyter-widgets/base", "_model_module_version": "1.5.0", "_view_count": null, "_view_module_version": "1.2.0", "_model_module": "@jupyter-widgets/controls" } }, "15696888463a4d668d7ff7e4f5c93ee3": { "model_module": "@jupyter-widgets/base", "model_name": "LayoutModel", "state": { "_view_name": "LayoutView", "grid_template_rows": null, "right": null, "justify_content": null, "_view_module": "@jupyter-widgets/base", "overflow": null, "_model_module_version": "1.2.0", "_view_count": null, "flex_flow": null, "width": null, "min_width": null, "border": null, "align_items": null, "bottom": null, "_model_module": "@jupyter-widgets/base", "top": null, "grid_column": null, "overflow_y": null, "overflow_x": null, "grid_auto_flow": null, "grid_area": null, "grid_template_columns": null, "flex": null, "_model_name": "LayoutModel", "justify_items": null, "grid_row": null, "max_height": null, "align_content": null, "visibility": null, "align_self": null, "height": null, "min_height": null, "padding": null, "grid_auto_rows": null, "grid_gap": null, "max_width": null, "order": null, "_view_module_version": "1.2.0", "grid_template_areas": null, "object_position": null, "object_fit": null, "grid_auto_columns": null, "margin": null, "display": null, "left": null } } } } }, "cells": [ { "cell_type": "markdown", "metadata": { "id": "view-in-github", "colab_type": "text" }, "source": [ "\"Open" ] }, { "cell_type": "markdown", "metadata": { "id": "tQsU9aGhmLPo", "colab_type": "text" }, "source": [ "# **HiveMind Level : 1**\n", "\n", "# Task 1\n", "\n", " **The world happiness\n", "index dataset for 2015, 2016 and 2017**\n", "\n", "Datasets source : [https://www.kaggle.com/unsdsn/world-happiness](https://www.kaggle.com/unsdsn/world-happiness)\n", "\n", "Raw csv files source : [https://github.com/Priyatham-sai-chand/Happiness/tree/master](https://github.com/Priyatham-sai-chand/Happiness/tree/master)" ] }, { "cell_type": "code", "metadata": { "id": "VP1EHLddnnsE", "colab_type": "code", "outputId": "50c9d266-0e96-439d-d9d4-26140bf49299", "colab": { "base_uri": "https://localhost:8080/", "height": 34 } }, "source": [ "#Packages\n", "import pandas as pd\n", "from pprint import pprint\n", "import matplotlib.pyplot as plt\n", "%matplotlib" ], "execution_count": 1, "outputs": [ { "output_type": "stream", "text": [ "Using matplotlib backend: agg\n" ], "name": "stdout" } ] }, { "cell_type": "code", "metadata": { "id": "yUHCdQe2F8ja", "colab_type": "code", "colab": {} }, "source": [ "\n", "#URLs contaning the raw csv files\n", "url_2015 = \"https://raw.githubusercontent.com/Priyatham-sai-chand/Happiness/master/2015.csv\"\n", "url_2016 = \"https://raw.githubusercontent.com/Priyatham-sai-chand/Happiness/master/2016.csv\"\n", "url_2017 = \"https://raw.githubusercontent.com/Priyatham-sai-chand/Happiness/master/2017.csv\"\n", "\n", "#intialising dataframes with the URLs Content\n", "df_2015 = pd.read_csv(url_2015)\n", "df_2016 = pd.read_csv(url_2016)\n", "df_2017 = pd.read_csv(url_2017)\n" ], "execution_count": 0, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "S0yp0ObZCAKa", "colab_type": "text" }, "source": [ "# Question 1 \n", "\n", "**Countries with a happiness score of less than 5.0**\n" ] }, { "cell_type": "code", "metadata": { "id": "QQPc4ZSniHLc", "colab_type": "code", "colab": {} }, "source": [ "def happiness_less_than_score(df,score):\n", " \"\"\"Gathers the country names with happiness score less than specified.\"\"\"\n", " if df.equals(df_2015):\n", " return df_2015['Country'][df_2015['Happiness Score'] < score]\n", " elif df.equals(df_2016):\n", " return df_2016['Country'][df_2016['Happiness Score'] < score]\n", " elif df.equals(df_2017):\n", " return df_2017['Country'][df_2017['Happiness.Score'] < score]\n", " \n", "\n" ], "execution_count": 0, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "VMwEAVyyCijU", "colab_type": "text" }, "source": [ "**Answer**" ] }, { "cell_type": "code", "metadata": { "id": "WoMb20oCvxY4", "colab_type": "code", "outputId": "15265a3f-127a-4a30-855c-b16d25d7b1ab", "colab": { "base_uri": "https://localhost:8080/", "height": 173 } }, "source": [ "### Run this cell ###\n", "\n", "result = happiness_less_than_score(df_2015,5.0)\n", "print(\"In Year 2015: \")\n", "print(result.tolist()) #pprint(result.tolist())\n", "print()\n", "result = happiness_less_than_score(df_2016,5.0)\n", "print(\"In Year 2016: \")\n", "print(result.tolist()) #pprint(result.tolist())\n", "print()\n", "result = happiness_less_than_score(df_2017,5.0)\n", "print(\"In Year 2017: \")\n", "print(result.tolist()) #pprint(result.tolist())" ], "execution_count": 4, "outputs": [ { "output_type": "stream", "text": [ "In Year 2015: \n", "['Mozambique', 'Albania', 'Bosnia and Herzegovina', 'Lesotho', 'Dominican Republic', 'Laos', 'Mongolia', 'Swaziland', 'Greece', 'Lebanon', 'Hungary', 'Honduras', 'Tajikistan', 'Tunisia', 'Palestinian Territories', 'Bangladesh', 'Iran', 'Ukraine', 'Iraq', 'South Africa', 'Ghana', 'Zimbabwe', 'Liberia', 'India', 'Sudan', 'Haiti', 'Congo (Kinshasa)', 'Nepal', 'Ethiopia', 'Sierra Leone', 'Mauritania', 'Kenya', 'Djibouti', 'Armenia', 'Botswana', 'Myanmar', 'Georgia', 'Malawi', 'Sri Lanka', 'Cameroon', 'Bulgaria', 'Egypt', 'Yemen', 'Angola', 'Mali', 'Congo (Brazzaville)', 'Comoros', 'Uganda', 'Senegal', 'Gabon', 'Niger', 'Cambodia', 'Tanzania', 'Madagascar', 'Central African Republic', 'Chad', 'Guinea', 'Ivory Coast', 'Burkina Faso', 'Afghanistan', 'Rwanda', 'Benin', 'Syria', 'Burundi', 'Togo']\n", "\n", "In Year 2016: \n", "['Tajikistan', 'Mongolia', 'Laos', 'Nigeria', 'Honduras', 'Iran', 'Zambia', 'Nepal', 'Palestinian Territories', 'Albania', 'Bangladesh', 'Sierra Leone', 'Iraq', 'Namibia', 'Cameroon', 'Ethiopia', 'South Africa', 'Sri Lanka', 'India', 'Myanmar', 'Egypt', 'Armenia', 'Kenya', 'Ukraine', 'Ghana', 'Congo (Kinshasa)', 'Georgia', 'Congo (Brazzaville)', 'Senegal', 'Bulgaria', 'Mauritania', 'Zimbabwe', 'Malawi', 'Sudan', 'Gabon', 'Mali', 'Haiti', 'Botswana', 'Comoros', 'Ivory Coast', 'Cambodia', 'Angola', 'Niger', 'South Sudan', 'Chad', 'Burkina Faso', 'Uganda', 'Yemen', 'Madagascar', 'Tanzania', 'Liberia', 'Guinea', 'Rwanda', 'Benin', 'Afghanistan', 'Togo', 'Syria', 'Burundi']\n", "\n", "In Year 2017: \n", "['Nepal', 'Mongolia', 'South Africa', 'Tunisia', 'Palestinian Territories', 'Egypt', 'Bulgaria', 'Sierra Leone', 'Cameroon', 'Iran', 'Albania', 'Bangladesh', 'Namibia', 'Kenya', 'Mozambique', 'Myanmar', 'Senegal', 'Zambia', 'Iraq', 'Gabon', 'Ethiopia', 'Sri Lanka', 'Armenia', 'India', 'Mauritania', 'Congo (Brazzaville)', 'Georgia', 'Congo (Kinshasa)', 'Mali', 'Ivory Coast', 'Cambodia', 'Sudan', 'Ghana', 'Ukraine', 'Uganda', 'Burkina Faso', 'Niger', 'Malawi', 'Chad', 'Zimbabwe', 'Lesotho', 'Angola', 'Afghanistan', 'Botswana', 'Benin', 'Madagascar', 'Haiti', 'Yemen', 'South Sudan', 'Liberia', 'Guinea', 'Togo', 'Rwanda', 'Syria', 'Tanzania', 'Burundi', 'Central African Republic']\n" ], "name": "stdout" } ] }, { "cell_type": "markdown", "metadata": { "id": "G81dLVMKHxP4", "colab_type": "text" }, "source": [ "# Question 2\n", "\n", " **Which is the unhappiest country in Sub-Saharan Africa?**" ] }, { "cell_type": "code", "metadata": { "id": "PuTbRNV1iKCn", "colab_type": "code", "colab": {} }, "source": [ "def unhappiest_in_region(df,region):\n", " \"\"\" Finds the least happiness score in the specified region.\"\"\"\n", " if df.equals(df_2015):\n", " df_temp = df_2015[df_2015['Region'] == region]\n", " return df_temp[df_temp['Happiness Score'] == df_temp['Happiness Score'].min()]\n", " elif df.equals(df_2016):\n", " df_temp = df_2016[df_2016['Region'] == region]\n", " return df_temp[df_temp['Happiness Score'] == df_temp['Happiness Score'].min()]\n", " elif df.equals(df_2017):\n", " # Since 2017 report doesn't contain regions they are explictly taken from the 2015 year's countries under that region.\n", "\n", " df_region_country = df_2015['Country'][df_2015['Region'] == region].to_frame()\n", " df_temp = df_2017[df_2017['Country'].isin(df_region_country['Country'])]\n", " return df_temp[df_temp['Happiness.Score'] == df_temp['Happiness.Score'].min()]\n", "\n", "\n" ], "execution_count": 0, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "KnBWfhCRnLX-", "colab_type": "text" }, "source": [ "**Answer:**" ] }, { "cell_type": "markdown", "metadata": { "id": "sAJozClfuzOg", "colab_type": "text" }, "source": [ "" ] }, { "cell_type": "code", "metadata": { "id": "Nhg53virJyIg", "colab_type": "code", "outputId": "50a6e85c-7c9e-431a-b062-07a457a12390", "colab": { "base_uri": "https://localhost:8080/", "height": 153 } }, "source": [ "### Run this cell ###\n", "\n", "result = unhappiest_in_region(df_2015,\"Sub-Saharan Africa\")\n", "print(\"In Year 2015: \")\n", "print(result['Country'].tolist()) \n", "print()\n", "result = unhappiest_in_region(df_2016,\"Sub-Saharan Africa\")\n", "print(\"In Year 2016: \")\n", "print(result['Country'].tolist()) \n", "print()\n", "result = unhappiest_in_region(df_2017,\"Sub-Saharan Africa\")\n", "print(\"In Year 2017: \")\n", "print(result['Country'].tolist()) " ], "execution_count": 6, "outputs": [ { "output_type": "stream", "text": [ "In Year 2015: \n", "['Togo']\n", "\n", "In Year 2016: \n", "['Burundi']\n", "\n", "In Year 2017: \n", "['Central African Republic']\n" ], "name": "stdout" } ] }, { "cell_type": "markdown", "metadata": { "id": "4_g7pwTToMFy", "colab_type": "text" }, "source": [ "# Question 3\n", "\n", "3. Compare the Unhappiest and happiest countries in each region" ] }, { "cell_type": "code", "metadata": { "id": "msP1YFy9oRtA", "colab_type": "code", "colab": {} }, "source": [ "def happiest_in_region(df,region):\n", " \"\"\" Finds the most happiness score in the specified region.\"\"\"\n", " if df.equals(df_2015):\n", " df_temp = df_2015[df_2015['Region'] == region]\n", " return df_temp[df_temp['Happiness Score'] == df_temp['Happiness Score'].max()]\n", " elif df.equals(df_2016):\n", " df_temp = df_2016[df_2016['Region'] == region]\n", " return df_temp[df_temp['Happiness Score'] == df_temp['Happiness Score'].max()]\n", " elif df.equals(df_2017):\n", " # Since 2017 report doesn't contain regions they are explictly taken from the 2015 year's countries under that region.\n", "\n", " df_region_country = df_2015['Country'][df_2015['Region'] == region].to_frame()\n", " df_temp = df_2017[df_2017['Country'].isin(df_region_country['Country'])]\n", " return df_temp[df_temp['Happiness.Score'] == df_temp['Happiness.Score'].max()]" ], "execution_count": 0, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "75LzYGVl_mNB", "colab_type": "text" }, "source": [ "**Answer**" ] }, { "cell_type": "code", "metadata": { "id": "APYCHnWqoSN4", "colab_type": "code", "outputId": "6ebc9569-259d-4b41-83eb-c16cfd936ccc", "colab": { "base_uri": "https://localhost:8080/", "height": 1000 } }, "source": [ "\n", "## Run this cell ##\n", "\n", "print('In the Year 2015 ')\n", "for region in df_2015['Region'].unique():\n", " print()\n", " print(region )\n", " print()\n", " result = unhappiest_in_region(df_2015,region) #from question 2\n", " result1 = happiest_in_region(df_2015,region)\n", " display(result1.append(result))\n", "\n", "print('In the Year 2016 ')\n", "for region in df_2016['Region'].unique():\n", " print\n", " print(region )\n", " print()\n", " result = unhappiest_in_region(df_2016,region) #from question 2\n", " result1 = happiest_in_region(df_2016,region)\n", " display(result1.append(result))\n", "\n", "print('In the Year 2017 ')\n", "for region in df_2015['Region'].unique():\n", " print()\n", " print(region )\n", " print()\n", " result = unhappiest_in_region(df_2017,region) #from question 2\n", " result1 = happiest_in_region(df_2017,region)\n", " display(result1.append(result))\n" ], "execution_count": 8, "outputs": [ { "output_type": "stream", "text": [ "In the Year 2015 \n", "\n", "Western Europe\n", "\n" ], "name": "stdout" }, { "output_type": "display_data", "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", "
CountryRegionHappiness RankHappiness ScoreStandard ErrorEconomy (GDP per Capita)FamilyHealth (Life Expectancy)FreedomTrust (Government Corruption)GenerosityDystopia Residual
0SwitzerlandWestern Europe17.5870.034111.396511.349510.941430.665570.419780.296782.51738
101GreeceWestern Europe1024.8570.050621.154060.929330.882130.076990.013970.000001.80101
\n", "
" ], "text/plain": [ " Country Region ... Generosity Dystopia Residual\n", "0 Switzerland Western Europe ... 0.29678 2.51738\n", "101 Greece Western Europe ... 0.00000 1.80101\n", "\n", "[2 rows x 12 columns]" ] }, "metadata": { "tags": [] } }, { "output_type": "stream", "text": [ "\n", "North America\n", "\n" ], "name": "stdout" }, { "output_type": "display_data", "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", "
CountryRegionHappiness RankHappiness ScoreStandard ErrorEconomy (GDP per Capita)FamilyHealth (Life Expectancy)FreedomTrust (Government Corruption)GenerosityDystopia Residual
4CanadaNorth America57.4270.035531.326291.322610.905630.632970.329570.458112.45176
14United StatesNorth America157.1190.038391.394511.247110.861790.546040.158900.401052.51011
\n", "
" ], "text/plain": [ " Country Region ... Generosity Dystopia Residual\n", "4 Canada North America ... 0.45811 2.45176\n", "14 United States North America ... 0.40105 2.51011\n", "\n", "[2 rows x 12 columns]" ] }, "metadata": { "tags": [] } }, { "output_type": "stream", "text": [ "\n", "Australia and New Zealand\n", "\n" ], "name": "stdout" }, { "output_type": "display_data", "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", "
CountryRegionHappiness RankHappiness ScoreStandard ErrorEconomy (GDP per Capita)FamilyHealth (Life Expectancy)FreedomTrust (Government Corruption)GenerosityDystopia Residual
8New ZealandAustralia and New Zealand97.2860.033711.250181.319670.908370.639380.429220.475012.26425
9AustraliaAustralia and New Zealand107.2840.040831.333581.309230.931560.651240.356370.435622.26646
\n", "
" ], "text/plain": [ " Country Region ... Generosity Dystopia Residual\n", "8 New Zealand Australia and New Zealand ... 0.47501 2.26425\n", "9 Australia Australia and New Zealand ... 0.43562 2.26646\n", "\n", "[2 rows x 12 columns]" ] }, "metadata": { "tags": [] } }, { "output_type": "stream", "text": [ "\n", "Middle East and Northern Africa\n", "\n" ], "name": "stdout" }, { "output_type": "display_data", "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", "
CountryRegionHappiness RankHappiness ScoreStandard ErrorEconomy (GDP per Capita)FamilyHealth (Life Expectancy)FreedomTrust (Government Corruption)GenerosityDystopia Residual
10IsraelMiddle East and Northern Africa117.2780.034701.228571.223930.913870.413190.077850.331723.08854
155SyriaMiddle East and Northern Africa1563.0060.050150.663200.474890.721930.156840.189060.471790.32858
\n", "
" ], "text/plain": [ " Country Region ... Generosity Dystopia Residual\n", "10 Israel Middle East and Northern Africa ... 0.33172 3.08854\n", "155 Syria Middle East and Northern Africa ... 0.47179 0.32858\n", "\n", "[2 rows x 12 columns]" ] }, "metadata": { "tags": [] } }, { "output_type": "stream", "text": [ "\n", "Latin America and Caribbean\n", "\n" ], "name": "stdout" }, { "output_type": "display_data", "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", "
CountryRegionHappiness RankHappiness ScoreStandard ErrorEconomy (GDP per Capita)FamilyHealth (Life Expectancy)FreedomTrust (Government Corruption)GenerosityDystopia Residual
11Costa RicaLatin America and Caribbean127.2260.044540.955781.237880.860270.633760.105830.254973.17728
118HaitiLatin America and Caribbean1194.5180.073310.266730.743020.388470.244250.171750.461872.24173
\n", "
" ], "text/plain": [ " Country Region ... Generosity Dystopia Residual\n", "11 Costa Rica Latin America and Caribbean ... 0.25497 3.17728\n", "118 Haiti Latin America and Caribbean ... 0.46187 2.24173\n", "\n", "[2 rows x 12 columns]" ] }, "metadata": { "tags": [] } }, { "output_type": "stream", "text": [ "\n", "Southeastern Asia\n", "\n" ], "name": "stdout" }, { "output_type": "display_data", "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", "
CountryRegionHappiness RankHappiness ScoreStandard ErrorEconomy (GDP per Capita)FamilyHealth (Life Expectancy)FreedomTrust (Government Corruption)GenerosityDystopia Residual
23SingaporeSoutheastern Asia246.7980.037801.521861.020001.025250.542520.492100.311051.88501
144CambodiaSoutheastern Asia1453.8190.050690.460380.627360.611140.662460.072470.403590.98195
\n", "
" ], "text/plain": [ " Country Region ... Generosity Dystopia Residual\n", "23 Singapore Southeastern Asia ... 0.31105 1.88501\n", "144 Cambodia Southeastern Asia ... 0.40359 0.98195\n", "\n", "[2 rows x 12 columns]" ] }, "metadata": { "tags": [] } }, { "output_type": "stream", "text": [ "\n", "Central and Eastern Europe\n", "\n" ], "name": "stdout" }, { "output_type": "display_data", "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", "
CountryRegionHappiness RankHappiness ScoreStandard ErrorEconomy (GDP per Capita)FamilyHealth (Life Expectancy)FreedomTrust (Government Corruption)GenerosityDystopia Residual
30Czech RepublicCentral and Eastern Europe316.5050.041681.178981.206430.844830.463640.026520.106862.67782
133BulgariaCentral and Eastern Europe1344.2180.048281.012161.106140.766490.305870.008720.119210.89991
\n", "
" ], "text/plain": [ " Country Region ... Generosity Dystopia Residual\n", "30 Czech Republic Central and Eastern Europe ... 0.10686 2.67782\n", "133 Bulgaria Central and Eastern Europe ... 0.11921 0.89991\n", "\n", "[2 rows x 12 columns]" ] }, "metadata": { "tags": [] } }, { "output_type": "stream", "text": [ "\n", "Eastern Asia\n", "\n" ], "name": "stdout" }, { "output_type": "display_data", "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", "
CountryRegionHappiness RankHappiness ScoreStandard ErrorEconomy (GDP per Capita)FamilyHealth (Life Expectancy)FreedomTrust (Government Corruption)GenerosityDystopia Residual
37TaiwanEastern Asia386.2980.038681.290981.076170.875300.397400.081290.253762.32323
99MongoliaEastern Asia1004.8740.033130.828191.300600.602680.436260.026660.332301.34759
\n", "
" ], "text/plain": [ " Country Region ... Generosity Dystopia Residual\n", "37 Taiwan Eastern Asia ... 0.25376 2.32323\n", "99 Mongolia Eastern Asia ... 0.33230 1.34759\n", "\n", "[2 rows x 12 columns]" ] }, "metadata": { "tags": [] } }, { "output_type": "stream", "text": [ "\n", "Sub-Saharan Africa\n", "\n" ], "name": "stdout" }, { "output_type": "display_data", "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", "
CountryRegionHappiness RankHappiness ScoreStandard ErrorEconomy (GDP per Capita)FamilyHealth (Life Expectancy)FreedomTrust (Government Corruption)GenerosityDystopia Residual
70MauritiusSub-Saharan Africa715.4770.071971.007610.985210.709500.560660.075210.377441.76145
157TogoSub-Saharan Africa1582.8390.067270.208680.139950.284430.364530.107310.166811.56726
\n", "
" ], "text/plain": [ " Country Region ... Generosity Dystopia Residual\n", "70 Mauritius Sub-Saharan Africa ... 0.37744 1.76145\n", "157 Togo Sub-Saharan Africa ... 0.16681 1.56726\n", "\n", "[2 rows x 12 columns]" ] }, "metadata": { "tags": [] } }, { "output_type": "stream", "text": [ "\n", "Southern Asia\n", "\n" ], "name": "stdout" }, { "output_type": "display_data", "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", "
CountryRegionHappiness RankHappiness ScoreStandard ErrorEconomy (GDP per Capita)FamilyHealth (Life Expectancy)FreedomTrust (Government Corruption)GenerosityDystopia Residual
78BhutanSouthern Asia795.2530.032250.770421.103950.574070.532060.154450.479981.63794
152AfghanistanSouthern Asia1533.5750.030840.319820.302850.303350.234140.097190.365101.95210
\n", "
" ], "text/plain": [ " Country Region ... Generosity Dystopia Residual\n", "78 Bhutan Southern Asia ... 0.47998 1.63794\n", "152 Afghanistan Southern Asia ... 0.36510 1.95210\n", "\n", "[2 rows x 12 columns]" ] }, "metadata": { "tags": [] } }, { "output_type": "stream", "text": [ "In the Year 2016 \n", "Western Europe\n", "\n" ], "name": "stdout" }, { "output_type": "display_data", "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", "
CountryRegionHappiness RankHappiness ScoreLower Confidence IntervalUpper Confidence IntervalEconomy (GDP per Capita)FamilyHealth (Life Expectancy)FreedomTrust (Government Corruption)GenerosityDystopia Residual
0DenmarkWestern Europe17.5267.4607.5921.441781.163740.795040.579410.444530.361712.73939
98GreeceWestern Europe995.0334.9355.1311.248860.754730.800290.058220.041270.000002.12944
\n", "
" ], "text/plain": [ " Country Region ... Generosity Dystopia Residual\n", "0 Denmark Western Europe ... 0.36171 2.73939\n", "98 Greece Western Europe ... 0.00000 2.12944\n", "\n", "[2 rows x 13 columns]" ] }, "metadata": { "tags": [] } }, { "output_type": "stream", "text": [ "North America\n", "\n" ], "name": "stdout" }, { "output_type": "display_data", "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", "
CountryRegionHappiness RankHappiness ScoreLower Confidence IntervalUpper Confidence IntervalEconomy (GDP per Capita)FamilyHealth (Life Expectancy)FreedomTrust (Government Corruption)GenerosityDystopia Residual
5CanadaNorth America67.4047.3357.4731.440151.096100.82760.573700.313290.448342.70485
12United StatesNorth America137.1047.0207.1881.507961.047820.77900.481630.148680.410772.72782
\n", "
" ], "text/plain": [ " Country Region ... Generosity Dystopia Residual\n", "5 Canada North America ... 0.44834 2.70485\n", "12 United States North America ... 0.41077 2.72782\n", "\n", "[2 rows x 13 columns]" ] }, "metadata": { "tags": [] } }, { "output_type": "stream", "text": [ "Australia and New Zealand\n", "\n" ], "name": "stdout" }, { "output_type": "display_data", "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", "
CountryRegionHappiness RankHappiness ScoreLower Confidence IntervalUpper Confidence IntervalEconomy (GDP per Capita)FamilyHealth (Life Expectancy)FreedomTrust (Government Corruption)GenerosityDystopia Residual
7New ZealandAustralia and New Zealand87.3347.2647.4041.360661.172780.830960.581470.419040.494012.47553
8AustraliaAustralia and New Zealand97.3137.2417.3851.444431.104760.851200.568370.323310.474072.54650
\n", "
" ], "text/plain": [ " Country Region ... Generosity Dystopia Residual\n", "7 New Zealand Australia and New Zealand ... 0.49401 2.47553\n", "8 Australia Australia and New Zealand ... 0.47407 2.54650\n", "\n", "[2 rows x 13 columns]" ] }, "metadata": { "tags": [] } }, { "output_type": "stream", "text": [ "Middle East and Northern Africa\n", "\n" ], "name": "stdout" }, { "output_type": "display_data", "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", "
CountryRegionHappiness RankHappiness ScoreLower Confidence IntervalUpper Confidence IntervalEconomy (GDP per Capita)FamilyHealth (Life Expectancy)FreedomTrust (Government Corruption)GenerosityDystopia Residual
10IsraelMiddle East and Northern Africa117.2677.1997.3351.337660.995370.849170.364320.087280.322883.31029
155SyriaMiddle East and Northern Africa1563.0692.9363.2020.747190.148660.629940.069120.172330.483970.81789
\n", "
" ], "text/plain": [ " Country Region ... Generosity Dystopia Residual\n", "10 Israel Middle East and Northern Africa ... 0.32288 3.31029\n", "155 Syria Middle East and Northern Africa ... 0.48397 0.81789\n", "\n", "[2 rows x 13 columns]" ] }, "metadata": { "tags": [] } }, { "output_type": "stream", "text": [ "Latin America and Caribbean\n", "\n" ], "name": "stdout" }, { "output_type": "display_data", "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", "
CountryRegionHappiness RankHappiness ScoreLower Confidence IntervalUpper Confidence IntervalEconomy (GDP per Capita)FamilyHealth (Life Expectancy)FreedomTrust (Government Corruption)GenerosityDystopia Residual
13Costa RicaLatin America and Caribbean147.0876.9997.1751.068791.021520.761460.552250.105470.225533.35168
135HaitiLatin America and Caribbean1364.0283.8934.1630.340970.295610.274940.120720.144760.479582.37116
\n", "
" ], "text/plain": [ " Country Region ... Generosity Dystopia Residual\n", "13 Costa Rica Latin America and Caribbean ... 0.22553 3.35168\n", "135 Haiti Latin America and Caribbean ... 0.47958 2.37116\n", "\n", "[2 rows x 13 columns]" ] }, "metadata": { "tags": [] } }, { "output_type": "stream", "text": [ "Southeastern Asia\n", "\n" ], "name": "stdout" }, { "output_type": "display_data", "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", "
CountryRegionHappiness RankHappiness ScoreLower Confidence IntervalUpper Confidence IntervalEconomy (GDP per Capita)FamilyHealth (Life Expectancy)FreedomTrust (Government Corruption)GenerosityDystopia Residual
21SingaporeSoutheastern Asia226.7396.6746.8041.645550.867580.947190.487700.469870.327061.99375
139CambodiaSoutheastern Asia1403.9073.7984.0160.556040.537500.424940.588520.080920.403391.31573
\n", "
" ], "text/plain": [ " Country Region ... Generosity Dystopia Residual\n", "21 Singapore Southeastern Asia ... 0.32706 1.99375\n", "139 Cambodia Southeastern Asia ... 0.40339 1.31573\n", "\n", "[2 rows x 13 columns]" ] }, "metadata": { "tags": [] } }, { "output_type": "stream", "text": [ "Central and Eastern Europe\n", "\n" ], "name": "stdout" }, { "output_type": "display_data", "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", "
CountryRegionHappiness RankHappiness ScoreLower Confidence IntervalUpper Confidence IntervalEconomy (GDP per Capita)FamilyHealth (Life Expectancy)FreedomTrust (Government Corruption)GenerosityDystopia Residual
26Czech RepublicCentral and Eastern Europe276.5966.5156.6771.309151.007930.763760.414180.039860.099292.96211
128BulgariaCentral and Eastern Europe1294.2174.1044.3301.113060.925420.678060.212190.006150.127931.15377
\n", "
" ], "text/plain": [ " Country Region ... Generosity Dystopia Residual\n", "26 Czech Republic Central and Eastern Europe ... 0.09929 2.96211\n", "128 Bulgaria Central and Eastern Europe ... 0.12793 1.15377\n", "\n", "[2 rows x 13 columns]" ] }, "metadata": { "tags": [] } }, { "output_type": "stream", "text": [ "Eastern Asia\n", "\n" ], "name": "stdout" }, { "output_type": "display_data", "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", "
CountryRegionHappiness RankHappiness ScoreLower Confidence IntervalUpper Confidence IntervalEconomy (GDP per Capita)FamilyHealth (Life Expectancy)FreedomTrust (Government Corruption)GenerosityDystopia Residual
34TaiwanEastern Asia346.3796.3056.4531.397290.926240.795650.323770.066300.254952.61523
100MongoliaEastern Asia1014.9074.8384.9760.988531.089830.554690.359720.032850.345391.53586
\n", "
" ], "text/plain": [ " Country Region ... Generosity Dystopia Residual\n", "34 Taiwan Eastern Asia ... 0.25495 2.61523\n", "100 Mongolia Eastern Asia ... 0.34539 1.53586\n", "\n", "[2 rows x 13 columns]" ] }, "metadata": { "tags": [] } }, { "output_type": "stream", "text": [ "Sub-Saharan Africa\n", "\n" ], "name": "stdout" }, { "output_type": "display_data", "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", "
CountryRegionHappiness RankHappiness ScoreLower Confidence IntervalUpper Confidence IntervalEconomy (GDP per Capita)FamilyHealth (Life Expectancy)FreedomTrust (Government Corruption)GenerosityDystopia Residual
65MauritiusSub-Saharan Africa665.6485.5075.7891.143720.756950.661890.461450.052030.369512.20223
156BurundiSub-Saharan Africa1572.9052.7323.0780.068310.234420.157470.043200.094190.202902.10404
\n", "
" ], "text/plain": [ " Country Region ... Generosity Dystopia Residual\n", "65 Mauritius Sub-Saharan Africa ... 0.36951 2.20223\n", "156 Burundi Sub-Saharan Africa ... 0.20290 2.10404\n", "\n", "[2 rows x 13 columns]" ] }, "metadata": { "tags": [] } }, { "output_type": "stream", "text": [ "Southern Asia\n", "\n" ], "name": "stdout" }, { "output_type": "display_data", "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", "
CountryRegionHappiness RankHappiness ScoreLower Confidence IntervalUpper Confidence IntervalEconomy (GDP per Capita)FamilyHealth (Life Expectancy)FreedomTrust (Government Corruption)GenerosityDystopia Residual
83BhutanSouthern Asia845.1965.1385.2540.852700.908360.497590.460740.161600.485461.82916
153AfghanistanSouthern Asia1543.3603.2883.4320.382270.110370.173440.164300.071120.312682.14558
\n", "
" ], "text/plain": [ " Country Region ... Generosity Dystopia Residual\n", "83 Bhutan Southern Asia ... 0.48546 1.82916\n", "153 Afghanistan Southern Asia ... 0.31268 2.14558\n", "\n", "[2 rows x 13 columns]" ] }, "metadata": { "tags": [] } }, { "output_type": "stream", "text": [ "In the Year 2017 \n", "\n", "Western Europe\n", "\n" ], "name": "stdout" }, { "output_type": "display_data", "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", "
CountryHappiness.RankHappiness.ScoreWhisker.highWhisker.lowEconomy..GDP.per.Capita.FamilyHealth..Life.Expectancy.FreedomGenerosityTrust..Government.Corruption.Dystopia.Residual
0Norway17.5377.5944457.4795561.6164631.5335240.7966670.6354230.3620120.3159642.277027
88Portugal895.1955.2850425.1049591.3151751.3670430.7958440.4984650.0951030.0158691.107683
\n", "
" ], "text/plain": [ " Country Happiness.Rank ... Trust..Government.Corruption. Dystopia.Residual\n", "0 Norway 1 ... 0.315964 2.277027\n", "88 Portugal 89 ... 0.015869 1.107683\n", "\n", "[2 rows x 12 columns]" ] }, "metadata": { "tags": [] } }, { "output_type": "stream", "text": [ "\n", "North America\n", "\n" ], "name": "stdout" }, { "output_type": "display_data", "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", "
CountryHappiness.RankHappiness.ScoreWhisker.highWhisker.lowEconomy..GDP.per.Capita.FamilyHealth..Life.Expectancy.FreedomGenerosityTrust..Government.Corruption.Dystopia.Residual
6Canada77.3167.3844037.2475971.4792041.4813490.8345580.6111010.4355400.2873722.187264
13United States146.9937.0746576.9113431.5462591.4199210.7742870.5057410.3925790.1356392.218113
\n", "
" ], "text/plain": [ " Country ... Dystopia.Residual\n", "6 Canada ... 2.187264\n", "13 United States ... 2.218113\n", "\n", "[2 rows x 12 columns]" ] }, "metadata": { "tags": [] } }, { "output_type": "stream", "text": [ "\n", "Australia and New Zealand\n", "\n" ], "name": "stdout" }, { "output_type": "display_data", "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", "
CountryHappiness.RankHappiness.ScoreWhisker.highWhisker.lowEconomy..GDP.per.Capita.FamilyHealth..Life.Expectancy.FreedomGenerosityTrust..Government.Corruption.Dystopia.Residual
7New Zealand87.3147.3795107.2484901.4057061.5481950.8167600.6140620.5000050.3828172.046456
9Australia107.2847.3566517.2113491.4844151.5100420.8438870.6016070.4776990.3011842.065211
\n", "
" ], "text/plain": [ " Country ... Dystopia.Residual\n", "7 New Zealand ... 2.046456\n", "9 Australia ... 2.065211\n", "\n", "[2 rows x 12 columns]" ] }, "metadata": { "tags": [] } }, { "output_type": "stream", "text": [ "\n", "Middle East and Northern Africa\n", "\n" ], "name": "stdout" }, { "output_type": "display_data", "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", "
CountryHappiness.RankHappiness.ScoreWhisker.highWhisker.lowEconomy..GDP.per.Capita.FamilyHealth..Life.Expectancy.FreedomGenerosityTrust..Government.Corruption.Dystopia.Residual
10Israel117.2137.2798537.1461461.3753821.3762900.8384040.4059890.3300830.0852422.801757
151Syria1523.4623.6636693.2603310.7771530.3961030.5005330.0815390.4936640.1513471.061574
\n", "
" ], "text/plain": [ " Country Happiness.Rank ... Trust..Government.Corruption. Dystopia.Residual\n", "10 Israel 11 ... 0.085242 2.801757\n", "151 Syria 152 ... 0.151347 1.061574\n", "\n", "[2 rows x 12 columns]" ] }, "metadata": { "tags": [] } }, { "output_type": "stream", "text": [ "\n", "Latin America and Caribbean\n", "\n" ], "name": "stdout" }, { "output_type": "display_data", "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", "
CountryHappiness.RankHappiness.ScoreWhisker.highWhisker.lowEconomy..GDP.per.Capita.FamilyHealth..Life.Expectancy.FreedomGenerosityTrust..Government.Corruption.Dystopia.Residual
11Costa Rica127.0797.1681126.9898881.1097061.4164040.7595090.5801320.2146130.1001072.898639
144Haiti1453.6033.7347153.4712850.3686100.6404500.2773210.0303700.4892040.0998721.697168
\n", "
" ], "text/plain": [ " Country ... Dystopia.Residual\n", "11 Costa Rica ... 2.898639\n", "144 Haiti ... 1.697168\n", "\n", "[2 rows x 12 columns]" ] }, "metadata": { "tags": [] } }, { "output_type": "stream", "text": [ "\n", "Southeastern Asia\n", "\n" ], "name": "stdout" }, { "output_type": "display_data", "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", "
CountryHappiness.RankHappiness.ScoreWhisker.highWhisker.lowEconomy..GDP.per.Capita.FamilyHealth..Life.Expectancy.FreedomGenerosityTrust..Government.Corruption.Dystopia.Residual
25Singapore266.5726.6367236.5072771.6922781.3538140.9494920.5498410.3459660.4643081.216362
128Cambodia1294.1684.2785184.0574830.6017651.0062380.4297830.6333760.3859230.0681061.042941
\n", "
" ], "text/plain": [ " Country ... Dystopia.Residual\n", "25 Singapore ... 1.216362\n", "128 Cambodia ... 1.042941\n", "\n", "[2 rows x 12 columns]" ] }, "metadata": { "tags": [] } }, { "output_type": "stream", "text": [ "\n", "Central and Eastern Europe\n", "\n" ], "name": "stdout" }, { "output_type": "display_data", "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", "
CountryHappiness.RankHappiness.ScoreWhisker.highWhisker.lowEconomy..GDP.per.Capita.FamilyHealth..Life.Expectancy.FreedomGenerosityTrust..Government.Corruption.Dystopia.Residual
22Czech Republic236.6096.6838626.5341381.3526821.4338850.7544440.4909460.0881070.0368732.451862
131Ukraine1324.0964.1854104.0065900.8946521.3945380.5759040.1229750.2700610.0230290.814382
\n", "
" ], "text/plain": [ " Country ... Dystopia.Residual\n", "22 Czech Republic ... 2.451862\n", "131 Ukraine ... 0.814382\n", "\n", "[2 rows x 12 columns]" ] }, "metadata": { "tags": [] } }, { "output_type": "stream", "text": [ "\n", "Eastern Asia\n", "\n" ], "name": "stdout" }, { "output_type": "display_data", "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", "
CountryHappiness.RankHappiness.ScoreWhisker.highWhisker.lowEconomy..GDP.per.Capita.FamilyHealth..Life.Expectancy.FreedomGenerosityTrust..Government.Corruption.Dystopia.Residual
50Japan515.9205.9907195.8492811.4169151.4363380.9134760.5056260.1205730.1637611.363224
99Mongolia1004.9555.0216804.8883201.0272361.4930110.5577830.3941440.3384640.0329021.111292
\n", "
" ], "text/plain": [ " Country Happiness.Rank ... Trust..Government.Corruption. Dystopia.Residual\n", "50 Japan 51 ... 0.163761 1.363224\n", "99 Mongolia 100 ... 0.032902 1.111292\n", "\n", "[2 rows x 12 columns]" ] }, "metadata": { "tags": [] } }, { "output_type": "stream", "text": [ "\n", "Sub-Saharan Africa\n", "\n" ], "name": "stdout" }, { "output_type": "display_data", "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", "
CountryHappiness.RankHappiness.ScoreWhisker.highWhisker.lowEconomy..GDP.per.Capita.FamilyHealth..Life.Expectancy.FreedomGenerosityTrust..Government.Corruption.Dystopia.Residual
63Mauritius645.6295.7298625.5281381.1893961.2095610.6380070.4912470.3609340.0421821.697584
154Central African Republic1552.6932.8648842.5211160.0000000.0000000.0187730.2708420.2808760.0565652.066005
\n", "
" ], "text/plain": [ " Country ... Dystopia.Residual\n", "63 Mauritius ... 1.697584\n", "154 Central African Republic ... 2.066005\n", "\n", "[2 rows x 12 columns]" ] }, "metadata": { "tags": [] } }, { "output_type": "stream", "text": [ "\n", "Southern Asia\n", "\n" ], "name": "stdout" }, { "output_type": "display_data", "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", "
CountryHappiness.RankHappiness.ScoreWhisker.highWhisker.lowEconomy..GDP.per.Capita.FamilyHealth..Life.Expectancy.FreedomGenerosityTrust..Government.Corruption.Dystopia.Residual
79Pakistan805.2695.3599845.1780160.7268840.6726910.4020480.2352150.3154460.1243482.792489
140Afghanistan1413.7943.8736613.7143380.4014770.5815430.1807470.1061800.3118710.0611582.150801
\n", "
" ], "text/plain": [ " Country ... Dystopia.Residual\n", "79 Pakistan ... 2.792489\n", "140 Afghanistan ... 2.150801\n", "\n", "[2 rows x 12 columns]" ] }, "metadata": { "tags": [] } } ] }, { "cell_type": "markdown", "metadata": { "id": "1xTbfYrPD0XC", "colab_type": "text" }, "source": [ "# Question 4\n", "\n", "**4.Countries that became unhappy between 2015 to 2017** \n", "\n", "Happiness Score\n", "\n", "A metric measured in 2015 by asking the sampled people the question: \"How would you rate your happiness on a scale of 0 to 10 where 10 is the happiest.\"\n", "\n", "As per the Metric, All the countries above 5 are considered to be \"happy\" and all the countries below the score of 5 are considered to be \"unhappy\"." ] }, { "cell_type": "code", "metadata": { "id": "4nC62RAOSflj", "colab_type": "code", "colab": {} }, "source": [ "def happiness_more_than_score(df,score):\n", " \"\"\"Gathers the country names with happiness score greater than specified.\"\"\"\n", " \n", " if df.equals(df_2015):\n", " return df_2015['Country'][df_2015['Happiness Score'] > score]\n", " elif df.equals(df_2016):\n", " return df_2016['Country'][df_2016['Happiness Score'] > score]\n", " elif df.equals(df_2017):\n", " return df_2017['Country'][df_2017['Happiness.Score'] > score]" ], "execution_count": 0, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "2hOy7fcHBpPo", "colab_type": "code", "colab": {} }, "source": [ "" ], "execution_count": 0, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "1da6g3JEFBNz", "colab_type": "text" }, "source": [ "**Answer**" ] }, { "cell_type": "code", "metadata": { "id": "HlJs38zPEfwS", "colab_type": "code", "outputId": "073448a3-8891-41ad-bcfa-c8e4124ff325", "colab": { "base_uri": "https://localhost:8080/", "height": 80 } }, "source": [ "## Run this cell ##\n", "\n", "df_happy = happiness_more_than_score(df_2015,5).to_frame()\n", "df_unhappy = happiness_less_than_score(df_2017,5).to_frame() #from Question 1\n", "\n", "display(df_unhappy[df_unhappy['Country'].isin(df_happy['Country'])])\n" ], "execution_count": 10, "outputs": [ { "output_type": "display_data", "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Country
115Zambia
\n", "
" ], "text/plain": [ " Country\n", "115 Zambia" ] }, "metadata": { "tags": [] } } ] }, { "cell_type": "markdown", "metadata": { "id": "Q07fZ_krRAbw", "colab_type": "text" }, "source": [ "# Question 5\n", "\n", "5. Find the country whose happiness decreased by the most amount\n", "\n", "**Answer**" ] }, { "cell_type": "markdown", "metadata": { "id": "7xgVeGhaDzeh", "colab_type": "text" }, "source": [ "" ] }, { "cell_type": "code", "metadata": { "id": "EtqKYWLrBqcu", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 80 }, "outputId": "e68e404b-d36b-49db-ce1f-75a0777920e9" }, "source": [ "## Run this cell ##\n", "\n", "df_before = df_2015[['Country','Happiness Score']]\n", "df_after = df_2017[['Country','Happiness.Score']]\n", "df_merge = pd.merge(df_before,df_after, on='Country')\n", "df_merge['difference'] = df_merge['Happiness.Score'] - df_merge['Happiness Score']\n", "display(df_merge[df_merge['difference'] == df_merge['difference'].min()])" ], "execution_count": 11, "outputs": [ { "output_type": "display_data", "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
CountryHappiness ScoreHappiness.Scoredifference
21Venezuela6.815.25-1.56
\n", "
" ], "text/plain": [ " Country Happiness Score Happiness.Score difference\n", "21 Venezuela 6.81 5.25 -1.56" ] }, "metadata": { "tags": [] } } ] }, { "cell_type": "markdown", "metadata": { "id": "mDHQGyPGL4DQ", "colab_type": "text" }, "source": [ "#Task 2\n", "\n", "In the same notebook write the script to download ​UDF101​ and\n", "bring the training dataset in this format: (Labels can be downloaded\n", "from ​here​)" ] }, { "cell_type": "code", "metadata": { "id": "IFEbl5VURGal", "colab_type": "code", "outputId": "fa004cf9-4ef5-4d0f-b52f-f20ec76b384b", "colab": { "base_uri": "https://localhost:8080/", "height": 136 } }, "source": [ "!pip install pyunpack\n", "!pip install patool\n", "!pip install clint" ], "execution_count": 12, "outputs": [ { "output_type": "stream", "text": [ "Requirement already satisfied: pyunpack in /usr/local/lib/python3.6/dist-packages (0.2.1)\n", "Requirement already satisfied: easyprocess in /usr/local/lib/python3.6/dist-packages (from pyunpack) (0.3)\n", "Requirement already satisfied: entrypoint2 in /usr/local/lib/python3.6/dist-packages (from pyunpack) (0.2.1)\n", "Requirement already satisfied: argparse in /usr/local/lib/python3.6/dist-packages (from entrypoint2->pyunpack) (1.4.0)\n", "Requirement already satisfied: patool in /usr/local/lib/python3.6/dist-packages (1.12)\n", "Requirement already satisfied: clint in /usr/local/lib/python3.6/dist-packages (0.5.1)\n", "Requirement already satisfied: args in /usr/local/lib/python3.6/dist-packages (from clint) (0.1.0)\n" ], "name": "stdout" } ] }, { "cell_type": "markdown", "metadata": { "id": "y8iOvPEUQpkl", "colab_type": "text" }, "source": [ "Importing and Downloading the files" ] }, { "cell_type": "code", "metadata": { "id": "uVWw1hiQB8dT", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 115, "referenced_widgets": [ "f24a2c9e820b4249ab63654b9ef56604", "e4dc73cf71714fd38dd09fd06a8608c7", "652720149f1843cd964a3fae5a32b6d7", "a5b643a5d4db43769c04ded49d2ba09e", "2859a8220b6340fcba1862b35fbe5b91", "cfa563330e4b45cd9a4197bdf9ec6757", "838f5f7533314ade8fa3859ef7f46bf1", "6a30b268827f42e78da55a27979ddf47", "d15b4d02e1d84ce9b218dde279f11c59", "446c92b5b92845249477c60af3f63faf", "d63d7a10beab42179bcd6b4f5a433a49", "771d95358ad64e9c8742e416e61261da", "767d69f1b35e4df8bb4e718772c02b20", "8741b1c90f514abc950d3cdf4d63b5bf", "52f2278bb6f04526a08a75db50680708", "15696888463a4d668d7ff7e4f5c93ee3" ] }, "outputId": "4429783e-b475-4c92-f131-36186ff751f2" }, "source": [ "import os\n", "import requests\n", "from tqdm.auto import tqdm\n", "from pyunpack import Archive\n", "from clint.textui import progress\n", "import shutil\n", "\n", "labels_url = \"https://www.crcv.ucf.edu/data/UCF101/UCF101TrainTestSplits-RecognitionTask.zip\"\n", "data_url = \"https://www.crcv.ucf.edu/data/UCF101/UCF101.rar\"\n", "\n", "\n", "os.chdir('/content')\n", "\n", "# labels file zip download\n", "r = requests.get(labels_url, stream=True)\n", "file_name = labels_url.split('/')[-1]\n", "with tqdm.wrapattr(open(file_name, \"wb\"), \"write\", miniters=1,\n", " total=int(r.headers.get('content-length', 0)),\n", " desc=file_name) as fout:\n", " for chunk in r.iter_content(chunk_size=4096):\n", " fout.write(chunk)\n", "\n", "os.chdir('/content')\n", "\n", "# data file zip download\n", "r = requests.get(data_url, stream=True)\n", "file_name = data_url.split('/')[-1]\n", "with tqdm.wrapattr(open(file_name, \"wb\"), \"write\", miniters=1,\n", " total=int(r.headers.get('content-length', 0)),\n", " desc=file_name) as fout:\n", " for chunk in r.iter_content(chunk_size=4096):\n", " fout.write(chunk)\n", "\n", " " ], "execution_count": 13, "outputs": [ { "output_type": "display_data", "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "f24a2c9e820b4249ab63654b9ef56604", "version_minor": 0, "version_major": 2 }, "text/plain": [ "HBox(children=(FloatProgress(value=0.0, description='UCF101TrainTestSplits-RecognitionTask.zip', max=113943.0,…" ] }, "metadata": { "tags": [] } }, { "output_type": "stream", "text": [ "\n" ], "name": "stdout" }, { "output_type": "display_data", "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "d15b4d02e1d84ce9b218dde279f11c59", "version_minor": 0, "version_major": 2 }, "text/plain": [ "HBox(children=(FloatProgress(value=0.0, description='UCF101.rar', max=6932971618.0, style=ProgressStyle(descri…" ] }, "metadata": { "tags": [] } }, { "output_type": "stream", "text": [ "\n" ], "name": "stdout" } ] }, { "cell_type": "code", "metadata": { "id": "I44l5JdWB82u", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 34 }, "outputId": "98b60e3a-d51f-4873-86f2-249705942754" }, "source": [ "try:\n", " Archive('UCF101.rar').extractall('/content')\n", "except Exception:\n", " print('The error is due to inconsistency in the rar to patool extractor The contents are safely extracted.')" ], "execution_count": 14, "outputs": [ { "output_type": "stream", "text": [ "The error is due to inconsistency in the rar to patool extractor The contents are safely extracted.\n" ], "name": "stdout" } ] }, { "cell_type": "code", "metadata": { "id": "xEM2TjFNMwpR", "colab_type": "code", "colab": {} }, "source": [ "try:\n", " Archive('UCF101TrainTestSplits-RecognitionTask.zip').extractall('/content')\n", "except Exception:\n", " print('The error is due to inconsistency in the rar to patool extractor The contents are safely extracted.')" ], "execution_count": 0, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "dapsXkoAMyZ0", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 51 }, "outputId": "f879a905-7cd4-452c-a0f7-07b0f8a32e0b" }, "source": [ "\n", "os.chdir('/content/ucfTrainTestlist')\n", "ucf_file_list = os.listdir()\n", "ucf_temp = ucf_file_list[0:-1]\n", "\n", "#Finding the names of the actions \n", "with open(ucf_file_list[-1],'r') as f:\n", " names = []\n", " for file in f:\n", " res = \"\".join(filter(lambda x: not x.isdigit(), file))\n", " names.append(res.strip().replace('\\n',''))\n", "#Root directory in content folder of the notebook\n", "os.chdir('/content')\n", "os.mkdir('ucf101_result')\n", "\n", "#Creating the subfolders of train and test \n", "os.chdir('/content/ucf101_result')\n", "for subroot in ucf_temp:\n", " subrootname,subrootextension = os.path.splitext(subroot)\n", " os.mkdir(subrootname)\n", "\n", "#Creating names of actions in every train and test folders\n", "os.chdir('/content/ucf101_result')\n", "for subroot in ucf_temp:\n", " subrootname,subrootextension = os.path.splitext(subroot)\n", " os.chdir('/content/ucf101_result/'+subrootname)\n", " for name in names:\n", " os.mkdir(name)\n", "\n", "print(\"File manipulation started... \")\n", "#Loopoing through the videos of UCF-101 to compare with video in the Labels\n", "for name in names:\n", " os.chdir('/content/UCF-101/' + name)\n", " videos = os.listdir()\n", " for video in videos: # video in the UCF-101\n", " for subroot in ucf_temp:\n", " os.chdir('/content/ucfTrainTestlist')\n", " subrootname,subrootextension = os.path.splitext(subroot)\n", " with open(subroot,'r') as f:\n", " for filepath in f:\n", " filename = filepath.split('/')[-1].strip()\n", " if( filename == video): # Comparison \n", " shutil.move('/content/UCF-101/'+name+'/'+video,'/content/ucf101_result/'+subrootname+'/'+name)\n", "\n", "\n", "\n", "print(\"File manipulation complete.\")" ], "execution_count": 16, "outputs": [ { "output_type": "stream", "text": [ "File manipulation started... \n", "File manipulation complete.\n" ], "name": "stdout" } ] } ] }