Last active
October 23, 2024 06:19
-
-
Save fenago/8c4d3c5ef693bea2754299b8990ad939 to your computer and use it in GitHub Desktop.
proj_7-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/8c4d3c5ef693bea2754299b8990ad939/proj_7-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": "W_XLWRi8nox3" | |
| }, | |
| "source": [ | |
| "# Project 7-1: Prepare the ramen data" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "id": "3Aj8aud8nox7" | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "# https://www.kaggle.com/residentmario/ramen-ratings\n", | |
| "import pandas as pd\n", | |
| "import seaborn as sns" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "UYU9cPUPnox-" | |
| }, | |
| "source": [ | |
| "## Tasks" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "id": "2ipQPFxBnox_", | |
| "outputId": "99695d80-33dd-4e02-d994-bfcff48ec6b0" | |
| }, | |
| "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": "Dfc4lLpUnoyA", | |
| "outputId": "ce139a7e-f3ae-4dc7-fc3c-5bd72ed840a9" | |
| }, | |
| "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", | |
| " <th>CountryMeanRating</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", | |
| " <td>3.981605</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", | |
| " <td>3.665402</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", | |
| " <td>3.457043</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", | |
| " <td>3.665402</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", | |
| " <td>3.395161</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 CountryMeanRating \n", | |
| "0 Japan 3.75 3.981605 \n", | |
| "1 Taiwan 1.00 3.665402 \n", | |
| "2 USA 2.25 3.457043 \n", | |
| "3 Taiwan 2.75 3.665402 \n", | |
| "4 India 3.75 3.395161 " | |
| ] | |
| }, | |
| "execution_count": 3, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "# 2\n", | |
| "data['CountryMeanRating'] = data.groupby('Country')['Stars'].transform(func='mean')\n", | |
| "data.head()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "id": "kb8WrAcQnoyB", | |
| "outputId": "90bf348d-02b6-4191-c4af-e278fe654fdf" | |
| }, | |
| "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 colspan=\"7\" halign=\"left\">Stars</th>\n", | |
| " </tr>\n", | |
| " <tr>\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": [ | |
| " Stars \n", | |
| "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": 7, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "# 3\n", | |
| "data.groupby(['Country','Style'])[['Stars']].mean().unstack('Style')[['Stars']]" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "id": "n8gTIkVAnoyB" | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "# 4\n", | |
| "def shorten_string(row):\n", | |
| " words = row.Variety.split(' ')\n", | |
| " words = words[:2]\n", | |
| " words.append('...')\n", | |
| " return ' '.join(words)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "id": "KwqMjxZ0noyC", | |
| "outputId": "cab9846c-ac98-4653-8638-fd7db1d411b3" | |
| }, | |
| "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", | |
| " <th>CountryMeanRating</th>\n", | |
| " <th>ShortVariety</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", | |
| " <td>3.981605</td>\n", | |
| " <td>T's Restaurant ...</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", | |
| " <td>3.665402</td>\n", | |
| " <td>Noodles Spicy ...</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", | |
| " <td>3.457043</td>\n", | |
| " <td>Cup Noodles ...</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", | |
| " <td>3.665402</td>\n", | |
| " <td>GGE Ramen ...</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", | |
| " <td>3.395161</td>\n", | |
| " <td>Singapore Curry ...</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 CountryMeanRating ShortVariety \n", | |
| "0 Japan 3.75 3.981605 T's Restaurant ... \n", | |
| "1 Taiwan 1.00 3.665402 Noodles Spicy ... \n", | |
| "2 USA 2.25 3.457043 Cup Noodles ... \n", | |
| "3 Taiwan 2.75 3.665402 GGE Ramen ... \n", | |
| "4 India 3.75 3.395161 Singapore Curry ... " | |
| ] | |
| }, | |
| "execution_count": 9, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "# 5\n", | |
| "data['ShortVariety'] = data.apply(shorten_string, axis=1)\n", | |
| "data.head()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "id": "VhOsF6UYnoyC", | |
| "outputId": "2bb1fdf0-3140-4ee8-aae9-0c16d4e2004b" | |
| }, | |
| "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>Variety</th>\n", | |
| " <th>Style</th>\n", | |
| " <th>Country</th>\n", | |
| " <th>Stars</th>\n", | |
| " <th>CountryMeanRating</th>\n", | |
| " <th>ShortVariety</th>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Brand</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>New Touch</th>\n", | |
| " <td>T's Restaurant Tantanmen</td>\n", | |
| " <td>Cup</td>\n", | |
| " <td>Japan</td>\n", | |
| " <td>3.75</td>\n", | |
| " <td>3.981605</td>\n", | |
| " <td>T's Restaurant ...</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Just Way</th>\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", | |
| " <td>3.665402</td>\n", | |
| " <td>Noodles Spicy ...</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Nissin</th>\n", | |
| " <td>Cup Noodles Chicken Vegetable</td>\n", | |
| " <td>Cup</td>\n", | |
| " <td>USA</td>\n", | |
| " <td>2.25</td>\n", | |
| " <td>3.457043</td>\n", | |
| " <td>Cup Noodles ...</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Wei Lih</th>\n", | |
| " <td>GGE Ramen Snack Tomato Flavor</td>\n", | |
| " <td>Pack</td>\n", | |
| " <td>Taiwan</td>\n", | |
| " <td>2.75</td>\n", | |
| " <td>3.665402</td>\n", | |
| " <td>GGE Ramen ...</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>Ching's Secret</th>\n", | |
| " <td>Singapore Curry</td>\n", | |
| " <td>Pack</td>\n", | |
| " <td>India</td>\n", | |
| " <td>3.75</td>\n", | |
| " <td>3.395161</td>\n", | |
| " <td>Singapore Curry ...</td>\n", | |
| " </tr>\n", | |
| " </tbody>\n", | |
| "</table>\n", | |
| "</div>" | |
| ], | |
| "text/plain": [ | |
| " Variety Style \\\n", | |
| "Brand \n", | |
| "New Touch T's Restaurant Tantanmen Cup \n", | |
| "Just Way Noodles Spicy Hot Sesame Spicy Hot Sesame Guan... Pack \n", | |
| "Nissin Cup Noodles Chicken Vegetable Cup \n", | |
| "Wei Lih GGE Ramen Snack Tomato Flavor Pack \n", | |
| "Ching's Secret Singapore Curry Pack \n", | |
| "\n", | |
| " Country Stars CountryMeanRating ShortVariety \n", | |
| "Brand \n", | |
| "New Touch Japan 3.75 3.981605 T's Restaurant ... \n", | |
| "Just Way Taiwan 1.00 3.665402 Noodles Spicy ... \n", | |
| "Nissin USA 2.25 3.457043 Cup Noodles ... \n", | |
| "Wei Lih Taiwan 2.75 3.665402 GGE Ramen ... \n", | |
| "Ching's Secret India 3.75 3.395161 Singapore Curry ... " | |
| ] | |
| }, | |
| "execution_count": 10, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "# 6\n", | |
| "data.set_index('Brand', inplace=True)\n", | |
| "data.head()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "id": "35M6AD5HnoyD" | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "# 7\n", | |
| "data.reset_index(inplace=True)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "id": "MbiHdZ-vnoyD" | |
| }, | |
| "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