{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Topic 10: Practice problems (pandas: Series, DataFrames, reading data)\n",
    "\n",
    "Asiman Data School, Module 1: Foundations of Python Programming. Week 5, Thursday.\n",
    "\n",
    "Fifteen problems in three levels, on the same ideas and at the same level as the lesson notebook.\n",
    "\n",
    "How to work\n",
    "\n",
    "- Write your code in the cell under each problem. The lines that are already in the cell read the input for you. Where a problem asks for a function, write it above those lines; until it is written, the cell stops with a NameError, and that is expected.\n",
    "- When the cell runs, a small box appears. Type the value there and press Enter. Several numbers on one line are typed with spaces between them.\n",
    "- Run your code with every row of the examples table and compare the output. Print exactly what the problem asks for.\n",
    "- A hint and one possible solution are under each problem. Open them only after you have tried.\n",
    "- The problems share the variables of the setup cell, so run that cell first. A problem that continues from another problem needs that problem's cell to be run before it.\n",
    "- The file orders.csv must be in the same folder as this notebook. On the Asiman Data School website it is already there.\n",
    "\n",
    "Tip: Start every problem by looking at the table: `df.head()`. Then ask two questions: which rows do I need, and which columns? Positions go into `iloc`, labels and column names into `loc`."
   ],
   "id": "t10p-000"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Setup\n",
    "\n",
    "Run this cell first. Every problem below uses what it creates."
   ],
   "id": "t10p-001"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "\n",
    "df = pd.read_csv(\"orders.csv\")"
   ],
   "id": "t10p-002"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Easy"
   ],
   "id": "t10p-003"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Problem 1. The first seven orders\n",
    "\n",
    "Print the first 7 rows of the orders table."
   ],
   "id": "t10p-004"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Write your code here"
   ],
   "id": "t10p-005"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<details>\n",
    "<summary><b>Show a hint</b></summary>\n",
    "\n",
    "`df.head()` gives 5 rows. A number in the parentheses changes how many.\n",
    "\n",
    "</details>\n",
    "\n",
    "<details>\n",
    "<summary><b>Show the solution</b></summary>\n",
    "\n",
    "```python\n",
    "print(df.head(7))\n",
    "```\n",
    "\n",
    "**Output**\n",
    "\n",
    "```\n",
    "         date customer      city  category     product   price  units  rating\n",
    "0  2025-01-01    Nigar      Baku      Home         Mug    8.50      2     5.0\n",
    "1  2025-01-03     Ziya  Lankaran  Clothing      Jacket  129.00      1     3.0\n",
    "2  2025-01-11     Anar     Ganja     Books    Cookbook   24.90      4     5.0\n",
    "3  2025-01-13    Gunel      Baku     Books    Cookbook   24.90      2     4.0\n",
    "4  2025-01-14    Leyla      Baku     Books  Dictionary   29.90      1     3.0\n",
    "5  2025-01-15    Elvin      Baku  Clothing       Jeans   64.90      1     4.0\n",
    "6  2025-01-15     Aida  Sumqayit      Tech    Keyboard   53.91      1     4.0\n",
    "```\n",
    "\n",
    "</details>"
   ],
   "id": "t10p-006"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Problem 2. Names and size\n",
    "\n",
    "Print the column names of the orders table as a list, and the number of rows. Two lines."
   ],
   "id": "t10p-007"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Write your code here"
   ],
   "id": "t10p-008"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<details>\n",
    "<summary><b>Show a hint</b></summary>\n",
    "\n",
    "`df.columns.tolist()` gives the names as a list. The number of rows is `len(df)`.\n",
    "\n",
    "</details>\n",
    "\n",
    "<details>\n",
    "<summary><b>Show the solution</b></summary>\n",
    "\n",
    "```python\n",
    "print(df.columns.tolist())\n",
    "print(len(df))\n",
    "```\n",
    "\n",
    "**Output**\n",
    "\n",
    "```\n",
    "['date', 'customer', 'city', 'category', 'product', 'price', 'units', 'rating']\n",
    "300\n",
    "```\n",
    "\n",
    "</details>"
   ],
   "id": "t10p-009"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Problem 3. The last customers\n",
    "\n",
    "Print the `customer` column of the last 4 orders."
   ],
   "id": "t10p-010"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Write your code here"
   ],
   "id": "t10p-011"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<details>\n",
    "<summary><b>Show a hint</b></summary>\n",
    "\n",
    "Choose the column first, `df[\"customer\"]`, then take its end with `.tail(4)`.\n",
    "\n",
    "</details>\n",
    "\n",
    "<details>\n",
    "<summary><b>Show the solution</b></summary>\n",
    "\n",
    "```python\n",
    "print(df[\"customer\"].tail(4))\n",
    "```\n",
    "\n",
    "**Output**\n",
    "\n",
    "```\n",
    "296    Leyla\n",
    "297    Konul\n",
    "298    Nigar\n",
    "299     Ziya\n",
    "Name: customer, dtype: str\n",
    "```\n",
    "\n",
    "</details>"
   ],
   "id": "t10p-012"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Problem 4. Orders in every city\n",
    "\n",
    "Print how many orders each city has."
   ],
   "id": "t10p-013"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Write your code here"
   ],
   "id": "t10p-014"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<details>\n",
    "<summary><b>Show a hint</b></summary>\n",
    "\n",
    "`value_counts()` on the column `city` counts how often every city appears.\n",
    "\n",
    "</details>\n",
    "\n",
    "<details>\n",
    "<summary><b>Show the solution</b></summary>\n",
    "\n",
    "```python\n",
    "print(df[\"city\"].value_counts())\n",
    "```\n",
    "\n",
    "**Output**\n",
    "\n",
    "```\n",
    "city\n",
    "Baku        128\n",
    "Ganja        54\n",
    "Sumqayit     48\n",
    "Quba         30\n",
    "Lankaran     22\n",
    "Shaki        10\n",
    "Name: count, dtype: int64\n",
    "```\n",
    "\n",
    "</details>"
   ],
   "id": "t10p-015"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Medium"
   ],
   "id": "t10p-016"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Problem 5. One order by its position\n",
    "\n",
    "Read a number `n`. Print the product and the price of the order at the position `n`, on one line.\n",
    "\n",
    "Examples\n",
    "\n",
    "| Input | Output |\n",
    "|---|---|\n",
    "| `42` | `Pillow 17.6` |\n",
    "| `0` | `Mug 8.5` |\n",
    "| `299` | `Textbook 39.9` |\n",
    "| `150` | `Dictionary 26.91` |\n",
    "| `-1` | `Textbook 39.9` |"
   ],
   "id": "t10p-017"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "asiman": {
     "typed": [
      "42"
     ]
    }
   },
   "outputs": [],
   "source": [
    "n = int(input())\n",
    "# Write your code here"
   ],
   "id": "t10p-018"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<details>\n",
    "<summary><b>Show a hint</b></summary>\n",
    "\n",
    "`df.iloc[n]` gives the row as a Series. Read its values with the column names: `row[\"product\"]`, `row[\"price\"]`.\n",
    "\n",
    "</details>\n",
    "\n",
    "<details>\n",
    "<summary><b>Show the solution</b></summary>\n",
    "\n",
    "```python\n",
    "n = int(input())\n",
    "row = df.iloc[n]\n",
    "print(row[\"product\"], row[\"price\"])\n",
    "```\n",
    "\n",
    "**Test cases**\n",
    "\n",
    "| Input | Output |\n",
    "|---|---|\n",
    "| `42` | `Pillow 17.6` |\n",
    "| `0` | `Mug 8.5` |\n",
    "| `299` | `Textbook 39.9` |\n",
    "| `150` | `Dictionary 26.91` |\n",
    "| `-1` | `Textbook 39.9` |\n",
    "\n",
    "</details>"
   ],
   "id": "t10p-019"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Problem 6. Five rows, three columns\n",
    "\n",
    "Print the rows at the positions 50 to 54 with the columns `date`, `product` and `units`."
   ],
   "id": "t10p-020"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Write your code here"
   ],
   "id": "t10p-021"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<details>\n",
    "<summary><b>Show a hint</b></summary>\n",
    "\n",
    "With `loc` the columns go in by name and the slice includes its end: `df.loc[50:54, [...]]`. With `iloc` the slice is `50:55`, and the columns are chosen afterwards.\n",
    "\n",
    "</details>\n",
    "\n",
    "<details>\n",
    "<summary><b>Show the solution</b></summary>\n",
    "\n",
    "```python\n",
    "print(df.loc[50:54, [\"date\", \"product\", \"units\"]])\n",
    "```\n",
    "\n",
    "**Output**\n",
    "\n",
    "```\n",
    "          date     product  units\n",
    "50  2025-03-19         Mug      3\n",
    "51  2025-03-20  Power bank      1\n",
    "52  2025-03-21  Smartwatch      1\n",
    "53  2025-03-23   Dumbbells      1\n",
    "54  2025-03-26  Dictionary      1\n",
    "```\n",
    "\n",
    "</details>"
   ],
   "id": "t10p-022"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Problem 7. The three highest prices\n",
    "\n",
    "Find the three orders with the highest price. Print the products of these orders as a list, then their prices as a list."
   ],
   "id": "t10p-023"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Write your code here"
   ],
   "id": "t10p-024"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<details>\n",
    "<summary><b>Show a hint</b></summary>\n",
    "\n",
    "`df.nlargest(3, \"price\")` gives the three rows. Store them, then print `top[\"product\"].tolist()` and `top[\"price\"].tolist()`.\n",
    "\n",
    "</details>\n",
    "\n",
    "<details>\n",
    "<summary><b>Show the solution</b></summary>\n",
    "\n",
    "```python\n",
    "top = df.nlargest(3, \"price\")\n",
    "print(top[\"product\"].tolist())\n",
    "print(top[\"price\"].tolist())\n",
    "```\n",
    "\n",
    "**Output**\n",
    "\n",
    "```\n",
    "['Smartwatch', 'Smartwatch', 'Smartwatch']\n",
    "[249.0, 249.0, 249.0]\n",
    "```\n",
    "\n",
    "</details>"
   ],
   "id": "t10p-025"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Problem 8. Orders of one category\n",
    "\n",
    "Read the name of a category. Print how many orders this category has.\n",
    "\n",
    "Examples\n",
    "\n",
    "| Input | Output |\n",
    "|---|---|\n",
    "| `Books` | `74` |\n",
    "| `Tech` | `68` |\n",
    "| `Home` | `56` |\n",
    "| `Clothing` | `54` |\n",
    "| `Sports` | `48` |"
   ],
   "id": "t10p-026"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "asiman": {
     "typed": [
      "Books"
     ]
    }
   },
   "outputs": [],
   "source": [
    "category = input()\n",
    "# Write your code here"
   ],
   "id": "t10p-027"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<details>\n",
    "<summary><b>Show a hint</b></summary>\n",
    "\n",
    "`df[\"category\"].value_counts()` is a Series, and the categories are its labels. Reach one count with the label: `counts[category]`.\n",
    "\n",
    "</details>\n",
    "\n",
    "<details>\n",
    "<summary><b>Show the solution</b></summary>\n",
    "\n",
    "```python\n",
    "category = input()\n",
    "counts = df[\"category\"].value_counts()\n",
    "print(counts[category])\n",
    "```\n",
    "\n",
    "**Test cases**\n",
    "\n",
    "| Input | Output |\n",
    "|---|---|\n",
    "| `Books` | `74` |\n",
    "| `Tech` | `68` |\n",
    "| `Home` | `56` |\n",
    "| `Clothing` | `54` |\n",
    "| `Sports` | `48` |\n",
    "\n",
    "</details>"
   ],
   "id": "t10p-028"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Problem 9. The largest order\n",
    "\n",
    "Add a column `total` (price times units). Print the largest total and the name of the customer who made that order. Two lines."
   ],
   "id": "t10p-029"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Write your code here"
   ],
   "id": "t10p-030"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<details>\n",
    "<summary><b>Show a hint</b></summary>\n",
    "\n",
    "`df[\"total\"] = df[\"price\"] * df[\"units\"]`. The largest value is `.max()`, and `.idxmax()` gives the label of its row. With the label, `df.loc[label, \"customer\"]` is the name.\n",
    "\n",
    "</details>\n",
    "\n",
    "<details>\n",
    "<summary><b>Show the solution</b></summary>\n",
    "\n",
    "```python\n",
    "df[\"total\"] = df[\"price\"] * df[\"units\"]\n",
    "print(df[\"total\"].max())\n",
    "print(df.loc[df[\"total\"].idxmax(), \"customer\"])\n",
    "```\n",
    "\n",
    "**Output**\n",
    "\n",
    "```\n",
    "448.2\n",
    "Ramin\n",
    "```\n",
    "\n",
    "</details>"
   ],
   "id": "t10p-031"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Medium-Hard"
   ],
   "id": "t10p-032"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Problem 10. Sorted by units, then by price\n",
    "\n",
    "Sort the orders by `units`, the largest first, and orders with the same number of units by `price`, the largest first. Print the first 4 rows with the columns `product`, `units` and `price`."
   ],
   "id": "t10p-033"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Write your code here"
   ],
   "id": "t10p-034"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<details>\n",
    "<summary><b>Show a hint</b></summary>\n",
    "\n",
    "Two columns in a list, and a list for the directions: `df.sort_values([\"units\", \"price\"], ascending=[False, False])`. Then choose the three columns and take `.head(4)`.\n",
    "\n",
    "</details>\n",
    "\n",
    "<details>\n",
    "<summary><b>Show the solution</b></summary>\n",
    "\n",
    "```python\n",
    "ordered = df.sort_values([\"units\", \"price\"], ascending=[False, False])\n",
    "print(ordered[[\"product\", \"units\", \"price\"]].head(4))\n",
    "```\n",
    "\n",
    "**Output**\n",
    "\n",
    "```\n",
    "      product  units  price\n",
    "93   Football      5  28.00\n",
    "58   Yoga mat      5  27.90\n",
    "264  Cookbook      5  24.90\n",
    "31   Cookbook      5  19.92\n",
    "```\n",
    "\n",
    "</details>"
   ],
   "id": "t10p-035"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Problem 11. All orders of one customer\n",
    "\n",
    "Make the customer names the row labels with `set_index` and store the result in `by_customer`. Print the columns `date`, `product` and `price` of all orders of the customer `Sona`."
   ],
   "id": "t10p-036"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Write your code here"
   ],
   "id": "t10p-037"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<details>\n",
    "<summary><b>Show a hint</b></summary>\n",
    "\n",
    "`by_customer = df.set_index(\"customer\")`. Then `by_customer.loc[\"Sona\", [...]]` gives every row with this label.\n",
    "\n",
    "</details>\n",
    "\n",
    "<details>\n",
    "<summary><b>Show the solution</b></summary>\n",
    "\n",
    "```python\n",
    "by_customer = df.set_index(\"customer\")\n",
    "print(by_customer.loc[\"Sona\", [\"date\", \"product\", \"price\"]])\n",
    "```\n",
    "\n",
    "**Output**\n",
    "\n",
    "```\n",
    "                date     product  price\n",
    "customer                               \n",
    "Sona      2025-03-10  Headphones   89.9\n",
    "Sona      2025-12-21    Keyboard   59.9\n",
    "```\n",
    "\n",
    "</details>"
   ],
   "id": "t10p-038"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Problem 12. Save the totals\n",
    "\n",
    "**This problem continues from Problem 9**: the table already has the column `total` from your answer there. Save the columns `date`, `product` and `total` into the file `totals.csv` without the row labels. Read the new file and print its `shape` and its first 3 rows."
   ],
   "id": "t10p-039"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Write your code here"
   ],
   "id": "t10p-040"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<details>\n",
    "<summary><b>Show a hint</b></summary>\n",
    "\n",
    "Choose the three columns with double brackets, then `.to_csv(\"totals.csv\", index=False)`. Read the file with `pd.read_csv` into a new variable. If Python says there is no column `total`, finish Problem 9 first.\n",
    "\n",
    "</details>\n",
    "\n",
    "<details>\n",
    "<summary><b>Show the solution</b></summary>\n",
    "\n",
    "```python\n",
    "df[[\"date\", \"product\", \"total\"]].to_csv(\"totals.csv\", index=False)\n",
    "check = pd.read_csv(\"totals.csv\")\n",
    "print(check.shape)\n",
    "print(check.head(3))\n",
    "```\n",
    "\n",
    "**Output**\n",
    "\n",
    "```\n",
    "(300, 3)\n",
    "         date   product  total\n",
    "0  2025-01-01       Mug   17.0\n",
    "1  2025-01-03    Jacket  129.0\n",
    "2  2025-01-11  Cookbook   99.6\n",
    "```\n",
    "\n",
    "</details>"
   ],
   "id": "t10p-041"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Problem 13. The share of every category\n",
    "\n",
    "Print the share of every category in the orders, in percent, rounded to 1 decimal."
   ],
   "id": "t10p-042"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Write your code here"
   ],
   "id": "t10p-043"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<details>\n",
    "<summary><b>Show a hint</b></summary>\n",
    "\n",
    "`value_counts(normalize=True)` gives shares between 0 and 1. Multiply by 100, then `.round(1)`.\n",
    "\n",
    "</details>\n",
    "\n",
    "<details>\n",
    "<summary><b>Show the solution</b></summary>\n",
    "\n",
    "```python\n",
    "shares = df[\"category\"].value_counts(normalize=True) * 100\n",
    "print(shares.round(1))\n",
    "```\n",
    "\n",
    "**Output**\n",
    "\n",
    "```\n",
    "category\n",
    "Books       24.7\n",
    "Tech        22.7\n",
    "Home        18.7\n",
    "Clothing    18.0\n",
    "Sports      16.0\n",
    "Name: proportion, dtype: float64\n",
    "```\n",
    "\n",
    "</details>"
   ],
   "id": "t10p-044"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Problem 14. The most ordered products\n",
    "\n",
    "Write a function `top_products(df, n)` that returns the `n` most often ordered products as a list.\n",
    "\n",
    "Examples\n",
    "\n",
    "| Input | Output |\n",
    "|---|---|\n",
    "| `3` | `['Dictionary', 'Cookbook', 'Keyboard']` |\n",
    "| `1` | `['Dictionary']` |\n",
    "| `4` | `['Dictionary', 'Cookbook', 'Keyboard', 'Headphones']` |"
   ],
   "id": "t10p-045"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "asiman": {
     "typed": [
      "3"
     ]
    }
   },
   "outputs": [],
   "source": [
    "# Write the function top_products(df, n) here\n",
    "\n",
    "n = int(input())\n",
    "print(top_products(df, n))"
   ],
   "id": "t10p-046"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<details>\n",
    "<summary><b>Show a hint</b></summary>\n",
    "\n",
    "`df[\"product\"].value_counts()` has the most frequent product first. Take `.head(n)`. The products are the labels of this Series: `.index.tolist()`.\n",
    "\n",
    "</details>\n",
    "\n",
    "<details>\n",
    "<summary><b>Show the solution</b></summary>\n",
    "\n",
    "```python\n",
    "def top_products(df, n):\n",
    "    counts = df[\"product\"].value_counts()\n",
    "    return counts.head(n).index.tolist()\n",
    "\n",
    "n = int(input())\n",
    "print(top_products(df, n))\n",
    "```\n",
    "\n",
    "**Test cases**\n",
    "\n",
    "| Input | Output |\n",
    "|---|---|\n",
    "| `3` | `['Dictionary', 'Cookbook', 'Keyboard']` |\n",
    "| `1` | `['Dictionary']` |\n",
    "| `4` | `['Dictionary', 'Cookbook', 'Keyboard', 'Headphones']` |\n",
    "\n",
    "</details>"
   ],
   "id": "t10p-047"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Problem 15. A changed copy\n",
    "\n",
    "Work on a copy of the table, `shop`, so that `df` stays as it is. In the copy, rename `units` to `quantity`, remove the column `rating`, and add a column `price_usd`: the price divided by 1.7, rounded to 2 decimals. Print the columns `product`, `price`, `quantity` and `price_usd` of the first 3 rows."
   ],
   "id": "t10p-048"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "shop = df.copy()\n",
    "# Write your code here"
   ],
   "id": "t10p-049"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<details>\n",
    "<summary><b>Show a hint</b></summary>\n",
    "\n",
    "`rename(columns={...})` and `drop(columns=[...])` give new tables: store them back in `shop`. The new column: `shop[\"price_usd\"] = (shop[\"price\"] / 1.7).round(2)`.\n",
    "\n",
    "</details>\n",
    "\n",
    "<details>\n",
    "<summary><b>Show the solution</b></summary>\n",
    "\n",
    "```python\n",
    "shop = df.copy()\n",
    "shop = shop.rename(columns={\"units\": \"quantity\"})\n",
    "shop = shop.drop(columns=[\"rating\"])\n",
    "shop[\"price_usd\"] = (shop[\"price\"] / 1.7).round(2)\n",
    "print(shop[[\"product\", \"price\", \"quantity\", \"price_usd\"]].head(3))\n",
    "```\n",
    "\n",
    "**Output**\n",
    "\n",
    "```\n",
    "    product  price  quantity  price_usd\n",
    "0       Mug    8.5         2       5.00\n",
    "1    Jacket  129.0         1      75.88\n",
    "2  Cookbook   24.9         4      14.65\n",
    "```\n",
    "\n",
    "</details>"
   ],
   "id": "t10p-050"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "When you have finished, compare your solutions with the hidden ones. A different solution that passes every example is just as good."
   ],
   "id": "t10p-051"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
