{ "cells": [ { "cell_type": "markdown", "id": "20c4fb93-cd57-49bd-a095-7b8baf467ae3", "metadata": {}, "source": [ "# Optimizing Santa's Workshop \n", "\n", "### Description: \n", "Hey friend, imagine you're a data analyst at the North Pole, responsible for helping Santa Claus optimize his workshop's operations. Your task is to analyze data from various toy production lines, inventory management, and gift deliveries to improve the overall efficiency of Santa's workshop. \n", "\n", "### Tasks:\n", "- **Toy Production Analysis:** Calculate the total production cost for each toy type, considering the material costs and labor hours. Use the 'toy_type', 'material_cost' and 'labor_hours' columns for this analysis.\n", "- **Inventory Management:** Identify the top 5 toys with the highest inventory levels and the longest storage times. Use the 'toy_type', 'inventory_level', and 'storage_time' columns for this analysis.\n", "- **Gift Delivery Optimization:** Group gift deliveries by region and calculate the average delivery time for each region. Use the 'region' and 'delivery_time' columns for this analysis." ] }, { "cell_type": "code", "execution_count": 1, "id": "a4eec7de-96e4-4853-875c-f3c0c5cda057", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Python version 3.11.7 | packaged by Anaconda, Inc. | (main, Dec 15 2023, 18:05:47) [MSC v.1916 64 bit (AMD64)]\n", "Pandas version 2.2.1\n", "Numpy version 1.26.4\n" ] } ], "source": [ "# import libraries\n", "import pandas as pd\n", "import numpy as np\n", "import sys\n", "\n", "print('Python version ' + sys.version)\n", "print('Pandas version ' + pd.__version__)\n", "print('Numpy version ' + np.__version__)" ] }, { "cell_type": "markdown", "id": "94be29a5-c4b1-4471-8e53-8a58c49e772b", "metadata": {}, "source": [ "# The Data \n", "\n", "The dataset consists of three main components: toy production, inventory, and gift delivery data, providing insights into Santa's workshop operations. It includes information on 1,000 toys, their production costs, inventory levels, and storage times, as well as data on 5,000 gift deliveries across four regions. \n", "\n", "# Columns \n", "- **toy_id:** Unique identifier for each toy\n", "- **toy_type:** Type of toy (Doll, Car, Train, or Puzzle)\n", "- **material_cost:** Cost of materials for each toy\n", "- **labor_hours:** Number of labor hours required to produce each toy\n", "- **production_quantity:** Quantity of each toy produced\n", "- **inventory_level:** Current inventory level for each toy\n", "- **storage_time:** Time each toy has been in storage\n", "- **delivery_id:** Unique identifier for each gift delivery\n", "- **region:** Region where each gift was delivered (North, South, East, or West)\n", "- **delivery_time:** Time taken to deliver each gift" ] }, { "cell_type": "code", "execution_count": 2, "id": "43392984-400e-4382-a326-5b65be16f5e4", "metadata": {}, "outputs": [], "source": [ "# set the seed\n", "np.random.seed(0)\n", "\n", "# generate toy production data\n", "toy_production_data = {\n", " 'toy_id': range(1, 1001),\n", " 'toy_type': np.random.choice(['Doll', 'Car', 'Train', 'Puzzle'], size=1000),\n", " 'material_cost': np.random.uniform(5, 15, size=1000),\n", " 'labor_hours': np.random.uniform(1, 5, size=1000),\n", " 'production_quantity': np.random.randint(100, 500, size=1000)\n", "}\n", "\n", "# generate inventory data\n", "inventory_data = {\n", " 'toy_id': range(1, 1001),\n", " 'toy_type': np.random.choice(['Doll', 'Car', 'Train', 'Puzzle'], size=1000),\n", " 'inventory_level': np.random.randint(50, 200, size=1000),\n", " 'storage_time': np.random.uniform(1, 12, size=1000)\n", "}\n", "\n", "# generate gift delivery data\n", "gift_delivery_data = {\n", " 'delivery_id': range(1, 5001),\n", " 'region': np.random.choice(['North', 'South', 'East', 'West'], size=5000),\n", " 'delivery_time': np.random.uniform(1, 10, size=5000)\n", "}\n", "\n", "# create the DataFrames\n", "toy_production = pd.DataFrame(toy_production_data)\n", "inventory = pd.DataFrame(inventory_data)\n", "gift_delivery = pd.DataFrame(gift_delivery_data)" ] }, { "cell_type": "markdown", "id": "ebcb42d5-72bc-42a2-a505-9c8248d9a8c6", "metadata": {}, "source": [ "Let us take a look at the data types for each of the three dataframes." ] }, { "cell_type": "code", "execution_count": 3, "id": "aea2e1cd-8e8d-4e63-b965-8bca5d983420", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "RangeIndex: 1000 entries, 0 to 999\n", "Data columns (total 5 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 toy_id 1000 non-null int64 \n", " 1 toy_type 1000 non-null object \n", " 2 material_cost 1000 non-null float64\n", " 3 labor_hours 1000 non-null float64\n", " 4 production_quantity 1000 non-null int32 \n", "dtypes: float64(2), int32(1), int64(1), object(1)\n", "memory usage: 35.3+ KB\n" ] } ], "source": [ "toy_production.info()" ] }, { "cell_type": "code", "execution_count": 4, "id": "b2f103ff-3b5a-45c4-9eaa-55aff46b6423", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "RangeIndex: 1000 entries, 0 to 999\n", "Data columns (total 4 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 toy_id 1000 non-null int64 \n", " 1 toy_type 1000 non-null object \n", " 2 inventory_level 1000 non-null int32 \n", " 3 storage_time 1000 non-null float64\n", "dtypes: float64(1), int32(1), int64(1), object(1)\n", "memory usage: 27.5+ KB\n" ] } ], "source": [ "inventory.info()" ] }, { "cell_type": "code", "execution_count": 5, "id": "7b0f2b9e-dd41-4c7a-9fde-048e4a72531d", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "RangeIndex: 5000 entries, 0 to 4999\n", "Data columns (total 3 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 delivery_id 5000 non-null int64 \n", " 1 region 5000 non-null object \n", " 2 delivery_time 5000 non-null float64\n", "dtypes: float64(1), int64(1), object(1)\n", "memory usage: 117.3+ KB\n" ] } ], "source": [ "gift_delivery.info()" ] }, { "cell_type": "markdown", "id": "38009881-a1e8-4e82-a7c5-919e7187c32e", "metadata": {}, "source": [ "# Toy Production Analysis\n", "Calculate the total production cost for each toy type, considering the material costs and labor hours. Use the 'toy_type', 'material_cost' and 'labor_hours' columns for this analysis. \n", "\n", "We will need to make a guess how much santa was paying the elves. I think the elves were making $15 per hour. Do you think this is a fair rate for a toy maker in the North Pole? \n", "\n", "From the data, it seems like the Doll is the toy that costs the most to produce." ] }, { "cell_type": "code", "execution_count": 10, "id": "b5cf7931-9d6e-4aca-9e0b-b785afbbe4a2", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "toy_type\n", "Doll 56.309188\n", "Puzzle 56.191277\n", "Car 55.255473\n", "Train 53.876938\n", "Name: total_production_cost, dtype: float64" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# hourly rate of $15\n", "hourly_rate = 15.0\n", "\n", "# calculate the total production cost per toy\n", "toy_production['total_production_cost'] = toy_production['material_cost'] + (toy_production['labor_hours'] * hourly_rate)\n", "\n", "# create group object\n", "group = toy_production.groupby(\"toy_type\")\n", "\n", "# calculate the average total production cost per toy\n", "group.mean()['total_production_cost'].sort_values(ascending=False)" ] }, { "cell_type": "markdown", "id": "cc87b6af-da3b-4416-97d2-b5f813ea9c05", "metadata": {}, "source": [ "# Inventory Management\n", "\n", "Identify the top 5 toys with the highest inventory levels and the longest storage times. Use the 'toy_type', 'inventory_level', and 'storage_time' columns for this analysis.\n", "\n", "Here we make use of the `sort_values` method and pass it two columns to sort. \n", "\n", "**Note:** the sort_values method sorts data in **ascending** order by default." ] }, { "cell_type": "code", "execution_count": 14, "id": "1dbd8340-8854-4a98-87a1-2b736d9456c1", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
toy_idtoy_typeinventory_levelstorage_time
6364Train19911.842191
591592Car1996.558659
535536Puzzle1996.109956
653654Car1993.807524
420421Puzzle1993.100684
\n", "
" ], "text/plain": [ " toy_id toy_type inventory_level storage_time\n", "63 64 Train 199 11.842191\n", "591 592 Car 199 6.558659\n", "535 536 Puzzle 199 6.109956\n", "653 654 Car 199 3.807524\n", "420 421 Puzzle 199 3.100684" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "inventory.sort_values(by=['inventory_level','storage_time'], ascending=[False, False]).head()" ] }, { "cell_type": "markdown", "id": "ec10f4cf-2e29-4b7d-a564-d71a822dcc1f", "metadata": {}, "source": [ "I also asked `meta.ai` the following question out of curiosity. \n", "\n", "> in pandas, when using the method sort_values, what if i want to sort by multiple columns and I want to sort each one differently.\n", "\n", "Here are a few followup questions you can try:\n", "- can i also use a dictionary to pick column and order type\n", "- so a list is the only way to pass columns and sort order in sort_values" ] }, { "cell_type": "markdown", "id": "9431f660-b3d9-4394-a5ef-afcfe95ae156", "metadata": {}, "source": [ "# Gift Delivery Optimization\n", "\n", "Group gift deliveries by region and calculate the average delivery time for each region. Use the 'region' and 'delivery_time' columns for this analysis." ] }, { "cell_type": "code", "execution_count": 16, "id": "95037c7e-9b83-4465-ada9-bbfd87e7aa8f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "region\n", "East 5.395364\n", "North 5.528587\n", "South 5.448332\n", "West 5.561135\n", "Name: delivery_time, dtype: float64" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# create group object\n", "group = gift_delivery.groupby('region')\n", "\n", "# calculate the average delivery time by region\n", "group.mean()['delivery_time']" ] }, { "cell_type": "code", "execution_count": 18, "id": "4de23a91-e19f-4132-80b0-9ba39013840c", "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAkkAAAGdCAYAAAAGx+eQAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8fJSN1AAAACXBIWXMAAA9hAAAPYQGoP6dpAAAg1UlEQVR4nO3deXDU9f3H8deXBBZISEgoEAILBGiQEChCFBElCYRLhpKWqccwQKrQqkENx1DRQUSogSJYjuJVh6Otg3Y46ihyiAkI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ABgQSQAAAAZEEgAAgAGRBAAAYEAkAQAAGPwPcyJyDIhkiWoAAAAASUVORK5CYII=", "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# we can also plot it!\n", "group.mean()['delivery_time'].plot.barh();" ] }, { "cell_type": "markdown", "id": "175ed71b-1a51-401a-b580-7aabfe9e083d", "metadata": {}, "source": [ "# Summary\n", "This tutorial used Pandas to analyze data from Santa's workshop, focusing on toy production, inventory management, and gift delivery optimization. The tutorial covered data generation, data frame creation, data analysis, and visualization.\n", "\n", "### Key Takeaways\n", "- Used the `groupby` method to group data by toy type and calculate total production costs\n", "- Utilized the `mean` method to calculate average values, such as average total production cost per toy and average delivery time by region\n", "- Employed the `sort_values` method to sort data by multiple columns, identifying top 5 toys with highest inventory levels and longest storage times\n", "- Used the `head` method to display the top rows of a sorted DataFrame\n", "- Applied the `plot.barh` method to visualize average delivery times by region" ] }, { "cell_type": "markdown", "id": "a1dc3930-0976-41d6-aefb-d3680352e509", "metadata": {}, "source": [ "

This tutorial was created by HEDARO

" ] } ], "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.11.7" } }, "nbformat": 4, "nbformat_minor": 5 }