Created
October 23, 2024 07:49
-
-
Save fenago/4604425c7eac427daa0f9ad11e5d8d38 to your computer and use it in GitHub Desktop.
proj_8-1_ramen.ipynb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "view-in-github", | |
| "colab_type": "text" | |
| }, | |
| "source": [ | |
| "<a href=\"https://colab.research.google.com/gist/fenago/4604425c7eac427daa0f9ad11e5d8d38/proj_8-1_ramen.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "HZmVVLNUWfZ_" | |
| }, | |
| "source": [ | |
| "# Project 8-1: Analyze the ramen data" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "id": "Q5lGYo0zWfaC" | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "# https://www.kaggle.com/residentmario/ramen-ratings\n", | |
| "import pandas as pd\n", | |
| "import seaborn as sns" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "XuGrMEQ_WfaE" | |
| }, | |
| "source": [ | |
| "## Tasks" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "id": "sibQUN2MWfaF", | |
| "outputId": "d00c45c6-a044-433d-8496-81e98dd5c752" | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/html": [ | |
| "<div>\n", | |
| "<style scoped>\n", | |
| " .dataframe tbody tr th:only-of-type {\n", | |
| " vertical-align: middle;\n", | |
| " }\n", | |
| "\n", | |
| " .dataframe tbody tr th {\n", | |
| " vertical-align: top;\n", | |
| " }\n", | |
| "\n", | |
| " .dataframe thead th {\n", | |
| " text-align: right;\n", | |
| " }\n", | |
| "</style>\n", | |
| "<table border=\"1\" class=\"dataframe\">\n", | |
| " <thead>\n", | |
| " <tr style=\"text-align: right;\">\n", | |
| " <th></th>\n", | |
| " <th>Brand</th>\n", | |
| " <th>Variety</th>\n", | |
| " <th>Style</th>\n", | |
| " <th>Country</th>\n", | |
| " <th>Stars</th>\n", | |
| " </tr>\n", | |
| " </thead>\n", | |
| " <tbody>\n", | |
| " <tr>\n", | |
| " <th>0</th>\n", | |
| " <td>New Touch</td>\n", | |
| " <td>T's Restaurant Tantanmen</td>\n", | |
| " <td>Cup</td>\n", | |
| " <td>Japan</td>\n", | |
| " <td>3.75</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>1</th>\n", | |
| " <td>Just Way</td>\n", | |
| " <td>Noodles Spicy Hot Sesame Spicy Hot Sesame Guan...</td>\n", | |
| " <td>Pack</td>\n", | |
| " <td>Taiwan</td>\n", | |
| " <td>1.00</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>2</th>\n", | |
| " <td>Nissin</td>\n", | |
| " <td>Cup Noodles Chicken Vegetable</td>\n", | |
| " <td>Cup</td>\n", | |
| " <td>USA</td>\n", | |
| " <td>2.25</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>3</th>\n", | |
| " <td>Wei Lih</td>\n", | |
| " <td>GGE Ramen Snack Tomato Flavor</td>\n", | |
| " <td>Pack</td>\n", | |
| " <td>Taiwan</td>\n", | |
| " <td>2.75</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>4</th>\n", | |
| " <td>Ching's Secret</td>\n", | |
| " <td>Singapore Curry</td>\n", | |
| " <td>Pack</td>\n", | |
| " <td>India</td>\n", | |
| " <td>3.75</td>\n", | |
| " </tr>\n", | |
| " </tbody>\n", | |
| "</table>\n", | |
| "</div>" | |
| ], | |
| "text/plain": [ | |
| " Brand Variety Style \\\n", | |
| "0 New Touch T's Restaurant Tantanmen Cup \n", | |
| "1 Just Way Noodles Spicy Hot Sesame Spicy Hot Sesame Guan... Pack \n", | |
| "2 Nissin Cup Noodles Chicken Vegetable Cup \n", | |
| "3 Wei Lih GGE Ramen Snack Tomato Flavor Pack \n", | |
| "4 Ching's Secret Singapore Curry Pack \n", | |
| "\n", | |
| " Country Stars \n", | |
| "0 Japan 3.75 \n", | |
| "1 Taiwan 1.00 \n", | |
| "2 USA 2.25 \n", | |
| "3 Taiwan 2.75 \n", | |
| "4 India 3.75 " | |
| ] | |
| }, | |
| "execution_count": 2, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "# 1\n", | |
| "data = pd.read_csv('ramen-ratings.csv')\n", | |
| "data.head()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "id": "gOaSRspWWfaH", | |
| "outputId": "9424bf26-97ec-4684-e4b3-d76d0cad89dd" | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/html": [ | |
| "<div>\n", | |
| "<style scoped>\n", | |
| " .dataframe tbody tr th:only-of-type {\n", | |
| " vertical-align: middle;\n", | |
| " }\n", | |
| "\n", | |
| " .dataframe tbody tr th {\n", | |
| " vertical-align: top;\n", | |
| " }\n", | |
| "\n", | |
| " .dataframe thead th {\n", | |
| " text-align: right;\n", | |
| " }\n", | |
| "</style>\n", | |
| "<table border=\"1\" class=\"dataframe\">\n", | |
| " <thead>\n", | |
| " <tr style=\"text-align: right;\">\n", | |
| " <th></th>\n", | |
| " <th></th>\n", | |
| " <th></th>\n", | |
| " <th>Stars</th>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Country</th>\n", | |
| " <th>Brand</th>\n", | |
| " <th>Style</th>\n", | |
| " <th></th>\n", | |
| " </tr>\n", | |
| " </thead>\n", | |
| " <tbody>\n", | |
| " <tr>\n", | |
| " <th rowspan=\"5\" valign=\"top\">Australia</th>\n", | |
| " <th>Fantastic</th>\n", | |
| " <th>Cup</th>\n", | |
| " <td>3.041667</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Maggi</th>\n", | |
| " <th>Pack</th>\n", | |
| " <td>5.000000</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Singa-Me</th>\n", | |
| " <th>Cup</th>\n", | |
| " <td>2.833333</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Suimin</th>\n", | |
| " <th>Cup</th>\n", | |
| " <td>3.287500</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Trident</th>\n", | |
| " <th>Pack</th>\n", | |
| " <td>2.750000</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>...</th>\n", | |
| " <th>...</th>\n", | |
| " <th>...</th>\n", | |
| " <td>...</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th rowspan=\"5\" valign=\"top\">Vietnam</th>\n", | |
| " <th>Vifon</th>\n", | |
| " <th>Pack</th>\n", | |
| " <td>2.877273</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th rowspan=\"4\" valign=\"top\">Vina Acecook</th>\n", | |
| " <th>Bowl</th>\n", | |
| " <td>3.812500</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Cup</th>\n", | |
| " <td>2.500000</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Pack</th>\n", | |
| " <td>3.535714</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Tray</th>\n", | |
| " <td>3.500000</td>\n", | |
| " </tr>\n", | |
| " </tbody>\n", | |
| "</table>\n", | |
| "<p>578 rows × 1 columns</p>\n", | |
| "</div>" | |
| ], | |
| "text/plain": [ | |
| " Stars\n", | |
| "Country Brand Style \n", | |
| "Australia Fantastic Cup 3.041667\n", | |
| " Maggi Pack 5.000000\n", | |
| " Singa-Me Cup 2.833333\n", | |
| " Suimin Cup 3.287500\n", | |
| " Trident Pack 2.750000\n", | |
| "... ...\n", | |
| "Vietnam Vifon Pack 2.877273\n", | |
| " Vina Acecook Bowl 3.812500\n", | |
| " Cup 2.500000\n", | |
| " Pack 3.535714\n", | |
| " Tray 3.500000\n", | |
| "\n", | |
| "[578 rows x 1 columns]" | |
| ] | |
| }, | |
| "execution_count": 4, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "# 2\n", | |
| "data.groupby(['Country','Brand','Style'])[['Stars']].mean()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "id": "9FbORRVSWfaH", | |
| "outputId": "ea933ce1-1f31-47cb-e33a-966e94fc1c41" | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/html": [ | |
| "<div>\n", | |
| "<style scoped>\n", | |
| " .dataframe tbody tr th:only-of-type {\n", | |
| " vertical-align: middle;\n", | |
| " }\n", | |
| "\n", | |
| " .dataframe tbody tr th {\n", | |
| " vertical-align: top;\n", | |
| " }\n", | |
| "\n", | |
| " .dataframe thead tr th {\n", | |
| " text-align: left;\n", | |
| " }\n", | |
| "\n", | |
| " .dataframe thead tr:last-of-type th {\n", | |
| " text-align: right;\n", | |
| " }\n", | |
| "</style>\n", | |
| "<table border=\"1\" class=\"dataframe\">\n", | |
| " <thead>\n", | |
| " <tr>\n", | |
| " <th></th>\n", | |
| " <th></th>\n", | |
| " <th></th>\n", | |
| " <th colspan=\"2\" halign=\"left\">Stars</th>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th></th>\n", | |
| " <th></th>\n", | |
| " <th></th>\n", | |
| " <th>mean</th>\n", | |
| " <th>count</th>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Country</th>\n", | |
| " <th>Brand</th>\n", | |
| " <th>Style</th>\n", | |
| " <th></th>\n", | |
| " <th></th>\n", | |
| " </tr>\n", | |
| " </thead>\n", | |
| " <tbody>\n", | |
| " <tr>\n", | |
| " <th rowspan=\"5\" valign=\"top\">Australia</th>\n", | |
| " <th>Fantastic</th>\n", | |
| " <th>Cup</th>\n", | |
| " <td>3.041667</td>\n", | |
| " <td>6</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Maggi</th>\n", | |
| " <th>Pack</th>\n", | |
| " <td>5.000000</td>\n", | |
| " <td>1</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Singa-Me</th>\n", | |
| " <th>Cup</th>\n", | |
| " <td>2.833333</td>\n", | |
| " <td>3</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Suimin</th>\n", | |
| " <th>Cup</th>\n", | |
| " <td>3.287500</td>\n", | |
| " <td>8</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Trident</th>\n", | |
| " <th>Pack</th>\n", | |
| " <td>2.750000</td>\n", | |
| " <td>4</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>...</th>\n", | |
| " <th>...</th>\n", | |
| " <th>...</th>\n", | |
| " <td>...</td>\n", | |
| " <td>...</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th rowspan=\"5\" valign=\"top\">Vietnam</th>\n", | |
| " <th>Vifon</th>\n", | |
| " <th>Pack</th>\n", | |
| " <td>2.877273</td>\n", | |
| " <td>22</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th rowspan=\"4\" valign=\"top\">Vina Acecook</th>\n", | |
| " <th>Bowl</th>\n", | |
| " <td>3.812500</td>\n", | |
| " <td>4</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Cup</th>\n", | |
| " <td>2.500000</td>\n", | |
| " <td>1</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Pack</th>\n", | |
| " <td>3.535714</td>\n", | |
| " <td>28</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Tray</th>\n", | |
| " <td>3.500000</td>\n", | |
| " <td>1</td>\n", | |
| " </tr>\n", | |
| " </tbody>\n", | |
| "</table>\n", | |
| "<p>578 rows × 2 columns</p>\n", | |
| "</div>" | |
| ], | |
| "text/plain": [ | |
| " Stars \n", | |
| " mean count\n", | |
| "Country Brand Style \n", | |
| "Australia Fantastic Cup 3.041667 6\n", | |
| " Maggi Pack 5.000000 1\n", | |
| " Singa-Me Cup 2.833333 3\n", | |
| " Suimin Cup 3.287500 8\n", | |
| " Trident Pack 2.750000 4\n", | |
| "... ... ...\n", | |
| "Vietnam Vifon Pack 2.877273 22\n", | |
| " Vina Acecook Bowl 3.812500 4\n", | |
| " Cup 2.500000 1\n", | |
| " Pack 3.535714 28\n", | |
| " Tray 3.500000 1\n", | |
| "\n", | |
| "[578 rows x 2 columns]" | |
| ] | |
| }, | |
| "execution_count": 12, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "# 3\n", | |
| "data.groupby(['Country','Brand','Style'])[['Stars']].agg(['mean','count'])" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "id": "kjJ6iXOZWfaI", | |
| "outputId": "8f858c8b-a6bb-4289-bcf4-d6e48e28e21a" | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/html": [ | |
| "<div>\n", | |
| "<style scoped>\n", | |
| " .dataframe tbody tr th:only-of-type {\n", | |
| " vertical-align: middle;\n", | |
| " }\n", | |
| "\n", | |
| " .dataframe tbody tr th {\n", | |
| " vertical-align: top;\n", | |
| " }\n", | |
| "\n", | |
| " .dataframe thead th {\n", | |
| " text-align: right;\n", | |
| " }\n", | |
| "</style>\n", | |
| "<table border=\"1\" class=\"dataframe\">\n", | |
| " <thead>\n", | |
| " <tr style=\"text-align: right;\">\n", | |
| " <th>Style</th>\n", | |
| " <th>Bar</th>\n", | |
| " <th>Bowl</th>\n", | |
| " <th>Box</th>\n", | |
| " <th>Can</th>\n", | |
| " <th>Cup</th>\n", | |
| " <th>Pack</th>\n", | |
| " <th>Tray</th>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Country</th>\n", | |
| " <th></th>\n", | |
| " <th></th>\n", | |
| " <th></th>\n", | |
| " <th></th>\n", | |
| " <th></th>\n", | |
| " <th></th>\n", | |
| " <th></th>\n", | |
| " </tr>\n", | |
| " </thead>\n", | |
| " <tbody>\n", | |
| " <tr>\n", | |
| " <th>Australia</th>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>3.120588</td>\n", | |
| " <td>3.200000</td>\n", | |
| " <td>NaN</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Bangladesh</th>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>3.714286</td>\n", | |
| " <td>NaN</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Brazil</th>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>4.500000</td>\n", | |
| " <td>4.250000</td>\n", | |
| " <td>NaN</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Cambodia</th>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>4.200000</td>\n", | |
| " <td>NaN</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Canada</th>\n", | |
| " <td>NaN</td>\n", | |
| " <td>2.281250</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>1.970588</td>\n", | |
| " <td>2.515625</td>\n", | |
| " <td>NaN</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>China</th>\n", | |
| " <td>NaN</td>\n", | |
| " <td>3.527778</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>2.859375</td>\n", | |
| " <td>3.538776</td>\n", | |
| " <td>2.583333</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Colombia</th>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>3.083333</td>\n", | |
| " <td>3.500000</td>\n", | |
| " <td>NaN</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Dubai</th>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>3.583333</td>\n", | |
| " <td>NaN</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Estonia</th>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>3.500000</td>\n", | |
| " <td>NaN</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Fiji</th>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>3.875000</td>\n", | |
| " <td>NaN</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Finland</th>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>3.583333</td>\n", | |
| " <td>NaN</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Germany</th>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>3.704545</td>\n", | |
| " <td>3.593750</td>\n", | |
| " <td>NaN</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Ghana</th>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>3.500000</td>\n", | |
| " <td>NaN</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Holland</th>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>3.562500</td>\n", | |
| " <td>NaN</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Hong Kong</th>\n", | |
| " <td>NaN</td>\n", | |
| " <td>3.735000</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>4.039474</td>\n", | |
| " <td>3.702239</td>\n", | |
| " <td>3.625000</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Hungary</th>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>3.611111</td>\n", | |
| " <td>NaN</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>India</th>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>2.583333</td>\n", | |
| " <td>3.482143</td>\n", | |
| " <td>NaN</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Indonesia</th>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>4.25</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>3.940476</td>\n", | |
| " <td>4.091346</td>\n", | |
| " <td>NaN</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Japan</th>\n", | |
| " <td>NaN</td>\n", | |
| " <td>4.140278</td>\n", | |
| " <td>5.00</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>3.940816</td>\n", | |
| " <td>3.801613</td>\n", | |
| " <td>4.375000</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Malaysia</th>\n", | |
| " <td>NaN</td>\n", | |
| " <td>4.281250</td>\n", | |
| " <td>5.00</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>4.011905</td>\n", | |
| " <td>4.156452</td>\n", | |
| " <td>NaN</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Mexico</th>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>3.733333</td>\n", | |
| " <td>3.725000</td>\n", | |
| " <td>NaN</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Myanmar</th>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>4.083333</td>\n", | |
| " <td>3.909091</td>\n", | |
| " <td>NaN</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Nepal</th>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>3.553571</td>\n", | |
| " <td>NaN</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Netherlands</th>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>1.333333</td>\n", | |
| " <td>2.770833</td>\n", | |
| " <td>NaN</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Nigeria</th>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>1.500000</td>\n", | |
| " <td>NaN</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Pakistan</th>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>3.000000</td>\n", | |
| " <td>NaN</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Philippines</th>\n", | |
| " <td>NaN</td>\n", | |
| " <td>3.375000</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>2.937500</td>\n", | |
| " <td>3.363636</td>\n", | |
| " <td>NaN</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Poland</th>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>3.625000</td>\n", | |
| " <td>NaN</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Sarawak</th>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>4.333333</td>\n", | |
| " <td>NaN</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Singapore</th>\n", | |
| " <td>NaN</td>\n", | |
| " <td>4.096154</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>3.925926</td>\n", | |
| " <td>4.210145</td>\n", | |
| " <td>NaN</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>South Korea</th>\n", | |
| " <td>NaN</td>\n", | |
| " <td>3.865809</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>3.500000</td>\n", | |
| " <td>3.857459</td>\n", | |
| " <td>3.479167</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Sweden</th>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>3.250000</td>\n", | |
| " <td>NaN</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Taiwan</th>\n", | |
| " <td>NaN</td>\n", | |
| " <td>3.263514</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>3.250000</td>\n", | |
| " <td>3.761326</td>\n", | |
| " <td>3.333333</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Thailand</th>\n", | |
| " <td>NaN</td>\n", | |
| " <td>3.142045</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>3.588542</td>\n", | |
| " <td>3.386598</td>\n", | |
| " <td>3.750000</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>UK</th>\n", | |
| " <td>NaN</td>\n", | |
| " <td>3.250000</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>2.978125</td>\n", | |
| " <td>3.000000</td>\n", | |
| " <td>NaN</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>USA</th>\n", | |
| " <td>5.0</td>\n", | |
| " <td>3.400000</td>\n", | |
| " <td>1.50</td>\n", | |
| " <td>3.5</td>\n", | |
| " <td>3.376786</td>\n", | |
| " <td>3.554688</td>\n", | |
| " <td>3.408654</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>United States</th>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>3.750000</td>\n", | |
| " <td>NaN</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Vietnam</th>\n", | |
| " <td>NaN</td>\n", | |
| " <td>3.362500</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>NaN</td>\n", | |
| " <td>2.656250</td>\n", | |
| " <td>3.183333</td>\n", | |
| " <td>3.750000</td>\n", | |
| " </tr>\n", | |
| " </tbody>\n", | |
| "</table>\n", | |
| "</div>" | |
| ], | |
| "text/plain": [ | |
| "Style Bar Bowl Box Can Cup Pack Tray\n", | |
| "Country \n", | |
| "Australia NaN NaN NaN NaN 3.120588 3.200000 NaN\n", | |
| "Bangladesh NaN NaN NaN NaN NaN 3.714286 NaN\n", | |
| "Brazil NaN NaN NaN NaN 4.500000 4.250000 NaN\n", | |
| "Cambodia NaN NaN NaN NaN NaN 4.200000 NaN\n", | |
| "Canada NaN 2.281250 NaN NaN 1.970588 2.515625 NaN\n", | |
| "China NaN 3.527778 NaN NaN 2.859375 3.538776 2.583333\n", | |
| "Colombia NaN NaN NaN NaN 3.083333 3.500000 NaN\n", | |
| "Dubai NaN NaN NaN NaN NaN 3.583333 NaN\n", | |
| "Estonia NaN NaN NaN NaN NaN 3.500000 NaN\n", | |
| "Fiji NaN NaN NaN NaN NaN 3.875000 NaN\n", | |
| "Finland NaN NaN NaN NaN NaN 3.583333 NaN\n", | |
| "Germany NaN NaN NaN NaN 3.704545 3.593750 NaN\n", | |
| "Ghana NaN NaN NaN NaN NaN 3.500000 NaN\n", | |
| "Holland NaN NaN NaN NaN NaN 3.562500 NaN\n", | |
| "Hong Kong NaN 3.735000 NaN NaN 4.039474 3.702239 3.625000\n", | |
| "Hungary NaN NaN NaN NaN NaN 3.611111 NaN\n", | |
| "India NaN NaN NaN NaN 2.583333 3.482143 NaN\n", | |
| "Indonesia NaN NaN 4.25 NaN 3.940476 4.091346 NaN\n", | |
| "Japan NaN 4.140278 5.00 NaN 3.940816 3.801613 4.375000\n", | |
| "Malaysia NaN 4.281250 5.00 NaN 4.011905 4.156452 NaN\n", | |
| "Mexico NaN NaN NaN NaN 3.733333 3.725000 NaN\n", | |
| "Myanmar NaN NaN NaN NaN 4.083333 3.909091 NaN\n", | |
| "Nepal NaN NaN NaN NaN NaN 3.553571 NaN\n", | |
| "Netherlands NaN NaN NaN NaN 1.333333 2.770833 NaN\n", | |
| "Nigeria NaN NaN NaN NaN NaN 1.500000 NaN\n", | |
| "Pakistan NaN NaN NaN NaN NaN 3.000000 NaN\n", | |
| "Philippines NaN 3.375000 NaN NaN 2.937500 3.363636 NaN\n", | |
| "Poland NaN NaN NaN NaN NaN 3.625000 NaN\n", | |
| "Sarawak NaN NaN NaN NaN NaN 4.333333 NaN\n", | |
| "Singapore NaN 4.096154 NaN NaN 3.925926 4.210145 NaN\n", | |
| "South Korea NaN 3.865809 NaN NaN 3.500000 3.857459 3.479167\n", | |
| "Sweden NaN NaN NaN NaN NaN 3.250000 NaN\n", | |
| "Taiwan NaN 3.263514 NaN NaN 3.250000 3.761326 3.333333\n", | |
| "Thailand NaN 3.142045 NaN NaN 3.588542 3.386598 3.750000\n", | |
| "UK NaN 3.250000 NaN NaN 2.978125 3.000000 NaN\n", | |
| "USA 5.0 3.400000 1.50 3.5 3.376786 3.554688 3.408654\n", | |
| "United States NaN NaN NaN NaN NaN 3.750000 NaN\n", | |
| "Vietnam NaN 3.362500 NaN NaN 2.656250 3.183333 3.750000" | |
| ] | |
| }, | |
| "execution_count": 6, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "# 4\n", | |
| "data.pivot_table(index='Country', columns='Style', values='Stars', aggfunc='mean')" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "id": "V7nuySKCWfaI", | |
| "outputId": "b255f8e4-2b53-4ba2-e4d8-fe1141e03347" | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "Country\n", | |
| "Australia 18.0\n", | |
| "Bangladesh 24.0\n", | |
| "Brazil 25.0\n", | |
| "Cambodia 26.0\n", | |
| "Canada 17.0\n", | |
| "China 7.0\n", | |
| "Colombia 27.0\n", | |
| "Dubai 32.5\n", | |
| "Estonia 35.5\n", | |
| "Fiji 28.0\n", | |
| "Finland 32.5\n", | |
| "Germany 15.0\n", | |
| "Ghana 35.5\n", | |
| "Holland 30.0\n", | |
| "Hong Kong 8.0\n", | |
| "Hungary 22.0\n", | |
| "India 14.0\n", | |
| "Indonesia 9.0\n", | |
| "Japan 1.0\n", | |
| "Malaysia 6.0\n", | |
| "Mexico 16.0\n", | |
| "Myanmar 19.0\n", | |
| "Nepal 20.0\n", | |
| "Netherlands 21.0\n", | |
| "Nigeria 38.0\n", | |
| "Pakistan 23.0\n", | |
| "Philippines 13.0\n", | |
| "Poland 29.0\n", | |
| "Sarawak 31.0\n", | |
| "Singapore 10.0\n", | |
| "South Korea 2.0\n", | |
| "Sweden 34.0\n", | |
| "Taiwan 4.0\n", | |
| "Thailand 5.0\n", | |
| "UK 12.0\n", | |
| "USA 3.0\n", | |
| "United States 37.0\n", | |
| "Vietnam 11.0\n", | |
| "Name: Stars, dtype: float64" | |
| ] | |
| }, | |
| "execution_count": 7, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "# 5\n", | |
| "data_grouped = data.groupby('Country').sum()\n", | |
| "data_grouped.Stars.rank(ascending=False)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "id": "RC4OMLMDWfaJ", | |
| "outputId": "d576fb36-dd56-497e-f738-26308adb8c0f" | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "Stars\n", | |
| "4.0 748\n", | |
| "3.5 509\n", | |
| "5.0 450\n", | |
| "4.5 284\n", | |
| "3.0 269\n", | |
| "2.0 91\n", | |
| "2.5 69\n", | |
| "1.5 65\n", | |
| "0.0 38\n", | |
| "1.0 38\n", | |
| "0.5 16\n", | |
| "Name: count, dtype: int64" | |
| ] | |
| }, | |
| "execution_count": 8, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "# 6\n", | |
| "pd.cut(data.Stars, bins=11, labels=[0,.5,1,1.5,2,2.5,3,3.5,4,4.5,5]).value_counts()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "id": "LatfYj2KWfaJ", | |
| "outputId": "56328b71-5d4d-4449-c30b-779029f2439b" | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "Stars\n", | |
| "Mediocre 749\n", | |
| "Terrible 583\n", | |
| "Bad 511\n", | |
| "Excellent 450\n", | |
| "Good 284\n", | |
| "Name: count, dtype: int64" | |
| ] | |
| }, | |
| "execution_count": 9, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "# 7\n", | |
| "pd.qcut(data.Stars, q=5, labels=['Terrible','Bad','Mediocre','Good','Excellent']).value_counts()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "IXioWw55WfaK" | |
| }, | |
| "source": [ | |
| "## Questions" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "id": "spkEK82VWfaK", | |
| "outputId": "b6741b15-6a7f-4690-caeb-302b55244436" | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/html": [ | |
| "<div>\n", | |
| "<style scoped>\n", | |
| " .dataframe tbody tr th:only-of-type {\n", | |
| " vertical-align: middle;\n", | |
| " }\n", | |
| "\n", | |
| " .dataframe tbody tr th {\n", | |
| " vertical-align: top;\n", | |
| " }\n", | |
| "\n", | |
| " .dataframe thead th {\n", | |
| " text-align: right;\n", | |
| " }\n", | |
| "</style>\n", | |
| "<table border=\"1\" class=\"dataframe\">\n", | |
| " <thead>\n", | |
| " <tr style=\"text-align: right;\">\n", | |
| " <th></th>\n", | |
| " <th>Brand</th>\n", | |
| " <th>Variety</th>\n", | |
| " <th>Style</th>\n", | |
| " <th>Stars</th>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Country</th>\n", | |
| " <th></th>\n", | |
| " <th></th>\n", | |
| " <th></th>\n", | |
| " <th></th>\n", | |
| " </tr>\n", | |
| " </thead>\n", | |
| " <tbody>\n", | |
| " <tr>\n", | |
| " <th>Japan</th>\n", | |
| " <td>New TouchAcecookIkeda ShokuRipe'n'DryNissinNis...</td>\n", | |
| " <td>T's Restaurant Tantanmen Spice Deli Tantan Men...</td>\n", | |
| " <td>CupCupTrayPackBowlBowlBowlTrayPackBowlBowlPack...</td>\n", | |
| " <td>1401.525</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>South Korea</th>\n", | |
| " <td>Samyang FoodsNongshimPaldoSamyang FoodsSamyang...</td>\n", | |
| " <td>Kimchi song Song RamenMr. Bibim Stir-Fried Kim...</td>\n", | |
| " <td>PackPackPackBowlPackPackPackBowlPackTrayBowlPa...</td>\n", | |
| " <td>1163.700</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>USA</th>\n", | |
| " <td>NissinYamachanYamachanJackpot TeriyakiYamachan...</td>\n", | |
| " <td>Cup Noodles Chicken VegetableYokohama Tonkotsu...</td>\n", | |
| " <td>CupPackPackPackPackBoxCupCupCupCanPackBowlBowl...</td>\n", | |
| " <td>1116.625</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Taiwan</th>\n", | |
| " <td>Just WayWei LihWei LihUni-PresidentMom's Dry N...</td>\n", | |
| " <td>Noodles Spicy Hot Sesame Spicy Hot Sesame Guan...</td>\n", | |
| " <td>PackPackPackBowlPackPackPackPackPackPackBowlBo...</td>\n", | |
| " <td>821.050</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Thailand</th>\n", | |
| " <td>Tao Kae NoiFashion FoodNissinMAMANissinNissinF...</td>\n", | |
| " <td>Creamy tom Yum Kung FlavourYummy Spicy Rice So...</td>\n", | |
| " <td>PackBowlCupBowlCupCupBowlCupBowlPackPackPackBo...</td>\n", | |
| " <td>646.500</td>\n", | |
| " </tr>\n", | |
| " </tbody>\n", | |
| "</table>\n", | |
| "</div>" | |
| ], | |
| "text/plain": [ | |
| " Brand \\\n", | |
| "Country \n", | |
| "Japan New TouchAcecookIkeda ShokuRipe'n'DryNissinNis... \n", | |
| "South Korea Samyang FoodsNongshimPaldoSamyang FoodsSamyang... \n", | |
| "USA NissinYamachanYamachanJackpot TeriyakiYamachan... \n", | |
| "Taiwan Just WayWei LihWei LihUni-PresidentMom's Dry N... \n", | |
| "Thailand Tao Kae NoiFashion FoodNissinMAMANissinNissinF... \n", | |
| "\n", | |
| " Variety \\\n", | |
| "Country \n", | |
| "Japan T's Restaurant Tantanmen Spice Deli Tantan Men... \n", | |
| "South Korea Kimchi song Song RamenMr. Bibim Stir-Fried Kim... \n", | |
| "USA Cup Noodles Chicken VegetableYokohama Tonkotsu... \n", | |
| "Taiwan Noodles Spicy Hot Sesame Spicy Hot Sesame Guan... \n", | |
| "Thailand Creamy tom Yum Kung FlavourYummy Spicy Rice So... \n", | |
| "\n", | |
| " Style Stars \n", | |
| "Country \n", | |
| "Japan CupCupTrayPackBowlBowlBowlTrayPackBowlBowlPack... 1401.525 \n", | |
| "South Korea PackPackPackBowlPackPackPackBowlPackTrayBowlPa... 1163.700 \n", | |
| "USA CupPackPackPackPackBoxCupCupCupCanPackBowlBowl... 1116.625 \n", | |
| "Taiwan PackPackPackBowlPackPackPackPackPackPackBowlBo... 821.050 \n", | |
| "Thailand PackBowlCupBowlCupCupBowlCupBowlPackPackPackBo... 646.500 " | |
| ] | |
| }, | |
| "execution_count": 10, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "# 1\n", | |
| "data_grouped.nlargest(n=5, columns='Stars')" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "id": "_PhZk2HpWfaL", | |
| "outputId": "41f470a7-47f6-4e4e-f416-5c0a5034c8a2" | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "66 USA\n", | |
| "Name: Country, dtype: object" | |
| ] | |
| }, | |
| "execution_count": 11, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "# 2\n", | |
| "data.query('Style == \"Can\"').Country" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "id": "Tl2Tce29WfaL" | |
| }, | |
| "outputs": [], | |
| "source": [] | |
| } | |
| ], | |
| "metadata": { | |
| "kernelspec": { | |
| "display_name": "Python 3 (ipykernel)", | |
| "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.9.18" | |
| }, | |
| "colab": { | |
| "provenance": [], | |
| "include_colab_link": true | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 0 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment