{
  "cells": [
    {
      "id": "84f4bcce-eaef-419b-86f9-4006f4b910cf",
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Midterm Examination: Example Problems\n"
      ]
    },
    {
      "id": "667a43c7-5686-49a2-943d-be8abeea1af5",
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Setup\n",
        "<small>준비</small>\n"
      ]
    },
    {
      "id": "b9b7acaa-a61d-4243-9268-1c8294158d33",
      "cell_type": "code",
      "execution_count": 1,
      "metadata": {},
      "outputs": [],
      "source": [
        "import numpy as np\n",
        "import pandas as pd\n",
        "\n",
        "file_path = \"uploads/campus_store_sales.csv\"\n"
      ]
    },
    {
      "id": "25a57bd1-be1a-4a9f-9d33-8f373ca27b7e",
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Problem 1. Load the CSV — Load `campus_store_sales.csv` into `sales_df` using pandas.\n",
        "<small>문제 1. CSV 불러오기 — `campus_store_sales.csv`를 pandas로 불러와 `sales_df`에 저장하세요.</small>\n"
      ]
    },
    {
      "id": "f2188b70-4922-434f-9d1e-bf951d49f548",
      "cell_type": "code",
      "execution_count": 2,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/plain": "    sale_id branch     category  ... quantity  unit_price  customer_rating\n0      1001      A   Stationery  ...        3         4.5              4.2\n1      1002      B        Snack  ...        5         2.0              4.5\n2      1003      C  Electronics  ...        2         9.0              4.0\n3      1004      A        Drink  ...        4         3.5              4.7\n4      1005      B   Stationery  ...        6         3.0              4.1\n5      1006      C        Snack  ...        2         5.5              4.3\n6      1007      A  Electronics  ...        1        18.0              4.6\n7      1008      B        Drink  ...        3         3.0              4.0\n8      1009      C   Stationery  ...        5         2.5              3.9\n9      1010      A        Snack  ...        4         2.2              4.4\n10     1011      B  Electronics  ...        1        28.0              4.8\n11     1012      C        Drink  ...        6         2.8              4.1\n12     1013      A   Stationery  ...        7         1.8              4.3\n13     1014      B        Snack  ...        3         5.5              4.2\n14     1015      C  Electronics  ...        4         9.0              4.6\n15     1016      A        Drink  ...        2         3.5              4.5\n16     1017      B   Stationery  ...        5         4.5              4.0\n17     1018      C        Snack  ...        6         2.0              4.4\n18     1019      A  Electronics  ...        2        18.0              4.7\n19     1020      B        Drink  ...        4         2.8              3.8\n20     1021      C   Stationery  ...        3         3.0              4.2\n21     1022      A        Snack  ...        5         5.5              NaN\n22     1023      B  Electronics  ...        3         9.0              4.1\n23     1024      C        Drink  ...        7         3.0              4.5\n24     1025      A   Stationery  ...        4         2.5              3.9\n25     1026      B        Snack  ...        8         2.2              4.6\n26     1027      C  Electronics  ...        1        28.0              4.9\n27     1028      A        Drink  ...        6         2.8              4.3\n28     1029      B   Stationery  ...        5         1.8              4.0\n29     1030      C        Snack  ...        4         2.0              4.2\n30     1031      A  Electronics  ...        2         9.0              4.4\n31     1032      B        Drink  ...        5         3.5              NaN\n32     1033      C   Stationery  ...        6         4.5              4.6\n33     1034      A        Snack  ...        3         2.2              4.1\n34     1035      B  Electronics  ...        2        18.0              4.7\n35     1036      C        Drink  ...        4         3.0              4.0\n36     1036      C        Drink  ...        4         3.0              4.0\n\n[37 rows x 7 columns]"
          },
          "execution_count": 2,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "sales_df = pd.read_csv(file_path)\n",
        "sales_df"
      ]
    },
    {
      "id": "e456c866-8b62-4608-aced-63ee0d2daada",
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Problem 2. Show the first rows — Show the first 5 rows of `sales_df`.\n",
        "<small>문제 2. 처음 행 확인 — `sales_df`의 처음 5개 행을 출력하세요.</small>\n"
      ]
    },
    {
      "id": "9d566b22-7c90-4003-b5c8-416374c43595",
      "cell_type": "code",
      "execution_count": 22,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/plain": "   sale_id branch     category  ... unit_price  customer_rating  revenue\n0     1001      A   Stationery  ...        4.5              4.2     13.5\n1     1002      B        Snack  ...        2.0              4.5     10.0\n2     1003      C  Electronics  ...        9.0              4.0     18.0\n3     1004      A        Drink  ...        3.5              4.7     14.0\n4     1005      B   Stationery  ...        3.0              4.1     18.0\n\n[5 rows x 8 columns]"
          },
          "execution_count": 22,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "sales_df.head(5)"
      ]
    },
    {
      "id": "712b3609-705b-40d1-958e-08473c534236",
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Problem 3. Check size and columns — Print the shape and column names of `sales_df`.\n",
        "<small>문제 3. 크기와 열 확인 — `sales_df`의 행·열 개수와 열 이름을 출력하세요.</small>\n"
      ]
    },
    {
      "id": "8e5e6803-9dfc-4c53-a2eb-f46f846554d5",
      "cell_type": "code",
      "execution_count": 4,
      "metadata": {},
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": "(37, 7)\nIndex(['sale_id', 'branch', 'category', 'product', 'quantity', 'unit_price',\n       'customer_rating'],\n      dtype='object')\n"
        }
      ],
      "source": [
        "print(sales_df.shape)\n",
        "print(sales_df.columns)"
      ]
    },
    {
      "id": "00cff8dc-7913-49f3-8b50-3c198f2278a0",
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Problem 4. Select one column — Select the `quantity` column.\n",
        "<small>문제 4. 열 하나 선택 — `quantity` 열을 선택하세요.</small>\n"
      ]
    },
    {
      "id": "814d7de9-31fa-426b-9229-2ac43e998f78",
      "cell_type": "code",
      "execution_count": 5,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/plain": "0     3\n1     5\n2     2\n3     4\n4     6\n5     2\n6     1\n7     3\n8     5\n9     4\n10    1\n11    6\n12    7\n13    3\n14    4\n15    2\n16    5\n17    6\n18    2\n19    4\n20    3\n21    5\n22    3\n23    7\n24    4\n25    8\n26    1\n27    6\n28    5\n29    4\n30    2\n31    5\n32    6\n33    3\n34    2\n35    4\n36    4\nName: quantity, dtype: int64"
          },
          "execution_count": 5,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "sales_df[\"quantity\"]"
      ]
    },
    {
      "id": "d1c95439-c5a2-4ed2-954f-005bd606bef2",
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Problem 5. Select multiple columns — Select `branch`, `category`, and `quantity`.\n",
        "<small>문제 5. 여러 열 선택 — `branch`, `category`, `quantity` 열을 선택하세요.</small>\n"
      ]
    },
    {
      "id": "eba54499-7417-4a84-85dd-c5bb551aa2b1",
      "cell_type": "code",
      "execution_count": 6,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/plain": "   branch     category  quantity\n0       A   Stationery         3\n1       B        Snack         5\n2       C  Electronics         2\n3       A        Drink         4\n4       B   Stationery         6\n5       C        Snack         2\n6       A  Electronics         1\n7       B        Drink         3\n8       C   Stationery         5\n9       A        Snack         4\n10      B  Electronics         1\n11      C        Drink         6\n12      A   Stationery         7\n13      B        Snack         3\n14      C  Electronics         4\n15      A        Drink         2\n16      B   Stationery         5\n17      C        Snack         6\n18      A  Electronics         2\n19      B        Drink         4\n20      C   Stationery         3\n21      A        Snack         5\n22      B  Electronics         3\n23      C        Drink         7\n24      A   Stationery         4\n25      B        Snack         8\n26      C  Electronics         1\n27      A        Drink         6\n28      B   Stationery         5\n29      C        Snack         4\n30      A  Electronics         2\n31      B        Drink         5\n32      C   Stationery         6\n33      A        Snack         3\n34      B  Electronics         2\n35      C        Drink         4\n36      C        Drink         4"
          },
          "execution_count": 6,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "sales_df[[\"branch\", \"category\", \"quantity\"]]"
      ]
    },
    {
      "id": "1c4c46a4-adf2-4812-b230-de2af7fb4384",
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Problem 6. Filter by branch — Show rows where `branch` is `B`.\n",
        "<small>문제 6. 지점으로 필터링 — `branch`가 `B`인 행만 출력하세요.</small>\n"
      ]
    },
    {
      "id": "92826a00-0611-45e6-93ec-bbdf1a114e02",
      "cell_type": "code",
      "execution_count": 7,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/plain": "    sale_id branch     category  ... quantity  unit_price  customer_rating\n1      1002      B        Snack  ...        5         2.0              4.5\n4      1005      B   Stationery  ...        6         3.0              4.1\n7      1008      B        Drink  ...        3         3.0              4.0\n10     1011      B  Electronics  ...        1        28.0              4.8\n13     1014      B        Snack  ...        3         5.5              4.2\n16     1017      B   Stationery  ...        5         4.5              4.0\n19     1020      B        Drink  ...        4         2.8              3.8\n22     1023      B  Electronics  ...        3         9.0              4.1\n25     1026      B        Snack  ...        8         2.2              4.6\n28     1029      B   Stationery  ...        5         1.8              4.0\n31     1032      B        Drink  ...        5         3.5              NaN\n34     1035      B  Electronics  ...        2        18.0              4.7\n\n[12 rows x 7 columns]"
          },
          "execution_count": 7,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "sales_df[sales_df[\"branch\"] == \"B\"]"
      ]
    },
    {
      "id": "e807e81a-88aa-4a24-972f-ba11a0465cf1",
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Problem 7. Filter by quantity — Show rows where `quantity` is 5 or more.\n",
        "<small>문제 7. 수량으로 필터링 — `quantity`가 5 이상인 행만 출력하세요.</small>\n"
      ]
    },
    {
      "id": "75d122fb-0e75-4183-b4c4-f6c5352e8895",
      "cell_type": "code",
      "execution_count": 8,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/plain": "    sale_id branch    category  ... quantity  unit_price  customer_rating\n1      1002      B       Snack  ...        5         2.0              4.5\n4      1005      B  Stationery  ...        6         3.0              4.1\n8      1009      C  Stationery  ...        5         2.5              3.9\n11     1012      C       Drink  ...        6         2.8              4.1\n12     1013      A  Stationery  ...        7         1.8              4.3\n16     1017      B  Stationery  ...        5         4.5              4.0\n17     1018      C       Snack  ...        6         2.0              4.4\n21     1022      A       Snack  ...        5         5.5              NaN\n23     1024      C       Drink  ...        7         3.0              4.5\n25     1026      B       Snack  ...        8         2.2              4.6\n27     1028      A       Drink  ...        6         2.8              4.3\n28     1029      B  Stationery  ...        5         1.8              4.0\n31     1032      B       Drink  ...        5         3.5              NaN\n32     1033      C  Stationery  ...        6         4.5              4.6\n\n[14 rows x 7 columns]"
          },
          "execution_count": 8,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "sales_df[sales_df[\"quantity\"] >= 5]"
      ]
    },
    {
      "id": "c60622f0-b1d2-4fd0-a545-7efb601fbaa8",
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Problem 8. Create a new column — Create `revenue = quantity * unit_price`.\n",
        "<small>문제 8. 새 열 만들기 — `revenue = quantity * unit_price`로 새 열을 만드세요.</small>\n"
      ]
    },
    {
      "id": "f4b90d28-8d34-4243-8006-2291f11e16c9",
      "cell_type": "code",
      "execution_count": 9,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/plain": "   sale_id branch     category  ... unit_price  customer_rating  revenue\n0     1001      A   Stationery  ...        4.5              4.2     13.5\n1     1002      B        Snack  ...        2.0              4.5     10.0\n2     1003      C  Electronics  ...        9.0              4.0     18.0\n3     1004      A        Drink  ...        3.5              4.7     14.0\n4     1005      B   Stationery  ...        3.0              4.1     18.0\n\n[5 rows x 8 columns]"
          },
          "execution_count": 9,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "sales_df[\"revenue\"] = sales_df[\"quantity\"] * sales_df[\"unit_price\"]\n",
        "sales_df.head()"
      ]
    },
    {
      "id": "a2e8a29f-05eb-4b14-b26b-5fc2d92212b9",
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Problem 9. Sort the data — Sort `sales_df` by `revenue` from highest to lowest.\n",
        "<small>문제 9. 데이터 정렬 — `sales_df`를 `revenue`가 큰 순서대로 정렬하세요.</small>\n"
      ]
    },
    {
      "id": "2a8d6ee0-b323-409f-bb55-42bc51a9d0a1",
      "cell_type": "code",
      "execution_count": 10,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/plain": "    sale_id branch     category  ... unit_price  customer_rating  revenue\n18     1019      A  Electronics  ...       18.0              4.7     36.0\n34     1035      B  Electronics  ...       18.0              4.7     36.0\n14     1015      C  Electronics  ...        9.0              4.6     36.0\n26     1027      C  Electronics  ...       28.0              4.9     28.0\n10     1011      B  Electronics  ...       28.0              4.8     28.0\n21     1022      A        Snack  ...        5.5              NaN     27.5\n32     1033      C   Stationery  ...        4.5              4.6     27.0\n22     1023      B  Electronics  ...        9.0              4.1     27.0\n16     1017      B   Stationery  ...        4.5              4.0     22.5\n23     1024      C        Drink  ...        3.0              4.5     21.0\n4      1005      B   Stationery  ...        3.0              4.1     18.0\n6      1007      A  Electronics  ...       18.0              4.6     18.0\n30     1031      A  Electronics  ...        9.0              4.4     18.0\n2      1003      C  Electronics  ...        9.0              4.0     18.0\n25     1026      B        Snack  ...        2.2              4.6     17.6\n31     1032      B        Drink  ...        3.5              NaN     17.5\n11     1012      C        Drink  ...        2.8              4.1     16.8\n27     1028      A        Drink  ...        2.8              4.3     16.8\n13     1014      B        Snack  ...        5.5              4.2     16.5\n3      1004      A        Drink  ...        3.5              4.7     14.0\n0      1001      A   Stationery  ...        4.5              4.2     13.5\n12     1013      A   Stationery  ...        1.8              4.3     12.6\n8      1009      C   Stationery  ...        2.5              3.9     12.5\n17     1018      C        Snack  ...        2.0              4.4     12.0\n35     1036      C        Drink  ...        3.0              4.0     12.0\n36     1036      C        Drink  ...        3.0              4.0     12.0\n19     1020      B        Drink  ...        2.8              3.8     11.2\n5      1006      C        Snack  ...        5.5              4.3     11.0\n1      1002      B        Snack  ...        2.0              4.5     10.0\n24     1025      A   Stationery  ...        2.5              3.9     10.0\n20     1021      C   Stationery  ...        3.0              4.2      9.0\n28     1029      B   Stationery  ...        1.8              4.0      9.0\n7      1008      B        Drink  ...        3.0              4.0      9.0\n9      1010      A        Snack  ...        2.2              4.4      8.8\n29     1030      C        Snack  ...        2.0              4.2      8.0\n15     1016      A        Drink  ...        3.5              4.5      7.0\n33     1034      A        Snack  ...        2.2              4.1      6.6\n\n[37 rows x 8 columns]"
          },
          "execution_count": 10,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "sales_df.sort_values(\"revenue\", ascending=False)"
      ]
    },
    {
      "id": "277a74d9-fbc9-4a6f-a0f0-a6519479821e",
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Problem 10. Check missing values — Count missing values in each column.\n",
        "<small>문제 10. 결측치 확인 — 각 열의 결측치 개수를 확인하세요.</small>\n"
      ]
    },
    {
      "id": "7af18125-e19d-4536-9529-f5be9a0bc82b",
      "cell_type": "code",
      "execution_count": 11,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/plain": "sale_id            0\nbranch             0\ncategory           0\nproduct            0\nquantity           0\nunit_price         0\ncustomer_rating    2\nrevenue            0\ndtype: int64"
          },
          "execution_count": 11,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "sales_df.isna().sum()"
      ]
    },
    {
      "id": "50e51842-9963-4444-8cb8-0171321a9f3a",
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Problem 11. Fill missing values — Fill missing `customer_rating` values with the mean rating.\n",
        "<small>문제 11. 결측치 채우기 — `customer_rating`의 결측치를 평균값으로 채우세요.</small>\n"
      ]
    },
    {
      "id": "2c42bee5-ed81-4038-bff7-964ddc6c0974",
      "cell_type": "code",
      "execution_count": 12,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/plain": "np.int64(0)"
          },
          "execution_count": 12,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "sales_df[\"customer_rating\"] = sales_df[\"customer_rating\"].fillna(sales_df[\"customer_rating\"].mean())\n",
        "sales_df[\"customer_rating\"].isna().sum()"
      ]
    },
    {
      "id": "b9de39ec-1b9d-49ec-b8b8-1899a4d37ac8",
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Problem 12. Remove duplicates — Remove duplicate rows and save the result as `clean_df`.\n",
        "<small>문제 12. 중복 제거 — 중복 행을 제거하고 결과를 `clean_df`에 저장하세요.</small>\n"
      ]
    },
    {
      "id": "6b89d6ec-309f-418c-aa7b-88e56f950520",
      "cell_type": "code",
      "execution_count": 13,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/plain": "    sale_id branch     category  ... unit_price  customer_rating  revenue\n0      1001      A   Stationery  ...        4.5         4.200000     13.5\n1      1002      B        Snack  ...        2.0         4.500000     10.0\n2      1003      C  Electronics  ...        9.0         4.000000     18.0\n3      1004      A        Drink  ...        3.5         4.700000     14.0\n4      1005      B   Stationery  ...        3.0         4.100000     18.0\n5      1006      C        Snack  ...        5.5         4.300000     11.0\n6      1007      A  Electronics  ...       18.0         4.600000     18.0\n7      1008      B        Drink  ...        3.0         4.000000      9.0\n8      1009      C   Stationery  ...        2.5         3.900000     12.5\n9      1010      A        Snack  ...        2.2         4.400000      8.8\n10     1011      B  Electronics  ...       28.0         4.800000     28.0\n11     1012      C        Drink  ...        2.8         4.100000     16.8\n12     1013      A   Stationery  ...        1.8         4.300000     12.6\n13     1014      B        Snack  ...        5.5         4.200000     16.5\n14     1015      C  Electronics  ...        9.0         4.600000     36.0\n15     1016      A        Drink  ...        3.5         4.500000      7.0\n16     1017      B   Stationery  ...        4.5         4.000000     22.5\n17     1018      C        Snack  ...        2.0         4.400000     12.0\n18     1019      A  Electronics  ...       18.0         4.700000     36.0\n19     1020      B        Drink  ...        2.8         3.800000     11.2\n20     1021      C   Stationery  ...        3.0         4.200000      9.0\n21     1022      A        Snack  ...        5.5         4.302857     27.5\n22     1023      B  Electronics  ...        9.0         4.100000     27.0\n23     1024      C        Drink  ...        3.0         4.500000     21.0\n24     1025      A   Stationery  ...        2.5         3.900000     10.0\n25     1026      B        Snack  ...        2.2         4.600000     17.6\n26     1027      C  Electronics  ...       28.0         4.900000     28.0\n27     1028      A        Drink  ...        2.8         4.300000     16.8\n28     1029      B   Stationery  ...        1.8         4.000000      9.0\n29     1030      C        Snack  ...        2.0         4.200000      8.0\n30     1031      A  Electronics  ...        9.0         4.400000     18.0\n31     1032      B        Drink  ...        3.5         4.302857     17.5\n32     1033      C   Stationery  ...        4.5         4.600000     27.0\n33     1034      A        Snack  ...        2.2         4.100000      6.6\n34     1035      B  Electronics  ...       18.0         4.700000     36.0\n35     1036      C        Drink  ...        3.0         4.000000     12.0\n\n[36 rows x 8 columns]"
          },
          "execution_count": 13,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "clean_df = sales_df.drop_duplicates()\n",
        "clean_df"
      ]
    },
    {
      "id": "8ebe998c-e56e-49a9-8d96-1402fcc21b58",
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Problem 13. Simple groupby — Find total `revenue` for each `branch` using `clean_df`.\n",
        "<small>문제 13. 간단한 groupby — `clean_df`에서 `branch`별 `revenue` 합계를 구하세요.</small>\n"
      ]
    },
    {
      "id": "53d801e3-a158-45a1-be55-1dc8517d5cf3",
      "cell_type": "code",
      "execution_count": 14,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/plain": "branch\nA    188.8\nB    222.3\nC    211.3\nName: revenue, dtype: float64"
          },
          "execution_count": 14,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "clean_df.groupby(\"branch\")[\"revenue\"].sum()"
      ]
    },
    {
      "id": "de83caa2-7f6e-4edb-8510-d71c9c580418",
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Problem 14. Make a NumPy array — Convert `clean_df['quantity']` to a NumPy array named `quantity_array`.\n",
        "<small>문제 14. NumPy 배열 만들기 — `clean_df['quantity']`를 NumPy 배열 `quantity_array`로 변환하세요.</small>\n"
      ]
    },
    {
      "id": "27c69e03-1568-49e7-ab55-34a2c7f616c6",
      "cell_type": "code",
      "execution_count": 15,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/plain": "array([3, 5, 2, 4, 6, 2, 1, 3, 5, 4, 1, 6, 7, 3, 4, 2, 5, 6, 2, 4, 3, 5,\n       3, 7, 4, 8, 1, 6, 5, 4, 2, 5, 6, 3, 2, 4], dtype=int64)"
          },
          "execution_count": 15,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "quantity_array = clean_df[\"quantity\"].to_numpy()\n",
        "quantity_array"
      ]
    },
    {
      "id": "f834d128-2d94-49c0-b23e-dd36b4853453",
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Problem 15. Check array information — Print the shape, number of dimensions, and data type of `quantity_array`.\n",
        "<small>문제 15. 배열 정보 확인 — `quantity_array`의 shape, 차원 수, 데이터 타입을 출력하세요.</small>\n"
      ]
    },
    {
      "id": "8ad5813e-8bb0-473b-ab84-06fad5241539",
      "cell_type": "code",
      "execution_count": 16,
      "metadata": {},
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": "(36,)\n1\nint64\n"
        }
      ],
      "source": [
        "print(quantity_array.shape)\n",
        "print(quantity_array.ndim)\n",
        "print(quantity_array.dtype)"
      ]
    },
    {
      "id": "8a717a53-fd27-4840-8901-7384d077c1b4",
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Problem 16. Index and slice — Print the first value and the first 5 values of `quantity_array`.\n",
        "<small>문제 16. 인덱싱과 슬라이싱 — `quantity_array`의 첫 번째 값과 처음 5개 값을 출력하세요.</small>\n"
      ]
    },
    {
      "id": "eee63f24-99f6-4507-9e60-2cea250e3c2e",
      "cell_type": "code",
      "execution_count": 17,
      "metadata": {},
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": "3\n[3 5 2 4 6]\n"
        }
      ],
      "source": [
        "print(quantity_array[0])\n",
        "print(quantity_array[:5])"
      ]
    },
    {
      "id": "03c600dd-e661-42a6-b717-7c60397449e1",
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Problem 17. Array calculation — Multiply every value in `quantity_array` by 2.\n",
        "<small>문제 17. 배열 계산 — `quantity_array`의 모든 값에 2를 곱하세요.</small>\n"
      ]
    },
    {
      "id": "d8d815cd-509e-4fa7-a9b5-678da7db9887",
      "cell_type": "code",
      "execution_count": 18,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/plain": "array([ 6, 10,  4,  8, 12,  4,  2,  6, 10,  8,  2, 12, 14,  6,  8,  4, 10,\n       12,  4,  8,  6, 10,  6, 14,  8, 16,  2, 12, 10,  8,  4, 10, 12,  6,\n        4,  8], dtype=int64)"
          },
          "execution_count": 18,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "quantity_array * 2"
      ]
    },
    {
      "id": "f3071122-c0db-46c2-91d5-281e69093623",
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Problem 18. NumPy filtering — Select values in `quantity_array` that are 5 or more.\n",
        "<small>문제 18. NumPy 필터링 — `quantity_array`에서 5 이상인 값만 선택하세요.</small>\n"
      ]
    },
    {
      "id": "cf2ce592-b263-41a1-96de-b5ed5b271a1b",
      "cell_type": "code",
      "execution_count": 19,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/plain": "array([5, 6, 5, 6, 7, 5, 6, 5, 7, 8, 6, 5, 5, 6], dtype=int64)"
          },
          "execution_count": 19,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "quantity_array[quantity_array >= 5]"
      ]
    },
    {
      "id": "197596dd-30d2-4e4b-9fca-0cd323ab0822",
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Problem 19. NumPy summary — Find the sum, mean, maximum, and minimum of `quantity_array`.\n",
        "<small>문제 19. NumPy 집계 — `quantity_array`의 합계, 평균, 최댓값, 최솟값을 구하세요.</small>\n"
      ]
    },
    {
      "id": "d749ac75-29e1-4f37-8bb6-9ef78d29e6ff",
      "cell_type": "code",
      "execution_count": 20,
      "metadata": {},
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": "143\n3.9722222222222223\n8\n1\n"
        }
      ],
      "source": [
        "print(np.sum(quantity_array))\n",
        "print(np.mean(quantity_array))\n",
        "print(np.max(quantity_array))\n",
        "print(np.min(quantity_array))"
      ]
    },
    {
      "id": "86d75c0f-c20a-4b6a-b27e-04785f9c11e4",
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Problem 20. Price array — Convert `unit_price` to `price_array`, then find its mean and maximum.\n",
        "<small>문제 20. 가격 배열 — `unit_price`를 `price_array`로 변환한 뒤 평균과 최댓값을 구하세요.</small>\n"
      ]
    },
    {
      "id": "e3dbdec1-851b-4339-8a43-948c77edf646",
      "cell_type": "code",
      "execution_count": 21,
      "metadata": {},
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": "6.419444444444444\n28.0\n"
        }
      ],
      "source": [
        "price_array = clean_df[\"unit_price\"].to_numpy()\n",
        "print(np.mean(price_array))\n",
        "print(np.max(price_array))"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3.12",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "name": "python",
      "version": "3.12"
    },
    "jspcv": {
      "runtime": "Pyodide 0.27.6",
      "local_files": [
        {
          "name": "campus_store_sales.csv",
          "size": 1351
        }
      ]
    }
  },
  "nbformat": 4,
  "nbformat_minor": 5
}
