216|PYTHON – Inventory Intel

BYU Student Author: @Kyle_Nilsen
Reviewers: @Trent_Barlow, @Marta_Ellsworth
Estimated Time to Solve: 40 Minutes

We provide the solution to this challenge using:

  • Python

Need a program? Click here.

Overview
You are working at a local grocer as an operations staff member and are tasked with inventory management. To track inventory changes, the cashiers input the day’s customer purchase receipts into a shared excel file, which you then use to tediously go between sheets and update the existing inventory values. After this, you send any items that are low in or out of stock to your colleagues in the purchasing department.
To improve the dated process currently in use, you take it upon yourself to create Python functions that will automatically track and update the daily inventory changes. The code you will write covers only today’s transactions, though it should function for any day as long as you are given the data.

Instructions

  1. Import the pandas module, and then import each sheet of the Store_Data.xlsx file into their own Dataframe. Afterwards, create a separate dictionary for each dataframe’s contents so that they can be easily manipulated. The dictionary keys should be the “Item” column, and the values should be the “Quantity” Column.
  2. Write a function called update_inventory that uses two arguments, inventory and delivery, to update the inventory based on the delivered items. If an item already exists in the inventory, the quantity should be updated. If an item is not present in the inventory, it should be added as a new entry to the dictionary.
  3. Write a function called process_transactions that takes two arguments, inventory and purchases, to update the inventory based on customer purchases. If an item’s quantity becomes zero due to a purchase, it should be removed from the inventory. In addition to updating the inventory, return the name of any item that has gone out of stock.
  4. Write a function called get_low_stock that takes two arguments, inventory and threshold, and returns a list of item names that have quantities below the specified threshold.
  5. Finally, update the inventory using the functions you have created. Create a variable called lowStock that is set to “5” to use in your get_low_stock function. Print any items that have gone completely out of stock, the items that are low in stock (below the threshold), and the ending inventory items and their quantities.

Data Files

Suggestions and Hints
  1. One possible solution involves using the .iterrows() function to easily pull in the items and quantities into a key value pair for your dictionaries.
  2. An easy way to iterate through the dictionary is to use a for loop on key, value in dictionary.items()
  3. To track the items that are deleted from being out of stock, create an empty list variable, and then append the item name to that list prior to deleting it from the dictionary
  4. You can return more than one item from a function if the function call is assigned to multiple variables.

Solution