Hi! My name is Allie Burke, I’m a Senior at The College of William and Mary.
I’m a Finance Major and Data Science Minor.
running
knitting
yoga
I wrote this sample script as a way to keep up with daily inventory changes at a small used bookstore that mostly has one copy of each book. It has the user load in two excel files that contain the inventory list and the sales made that day. My script checks to see which books were purchased, and returns an excel file with the new inventory list that can be used for the next day.
#!/usr/bin/env python3
#
# Book_keeping.py
#
#
# LAST EDIT: 2020-02-09
#
# This script compares entries in inventory and sales lists.
#
##############################################################################
# REQUIRED MODULES
##############################################################################
import pandas as pd
= []
inventory = []
booksales
def Book_keeping(Inventory, Daily_sales):
#reads in the two excel files
= pd.read_excel(Inventory)
Inventory = pd.read_excel(Daily_sales)
Today_total
#converts the idCode columns in each sheet into integers
for num in Inventory["idCode"]:
int(num)
for digit in Today_total["idCode"]:
int(digit)
#iterates over the idCode column and creates a list for both sheets
for copies in Inventory["idCode"]:
inventory.append(copies)for book in Today_total["idCode"]:
booksales.append(book)
#Calculates where the new day's inventory will appear in the excel sheet
= (len(inventory)-len(booksales))
tail
#removes purchased books from the inventory
for book in booksales:
inventory.remove(book)
#adds the new inventory to the excel sheet
for a in inventory:
for part in Inventory["idCode"]:
if a == part:
= Inventory.append(Inventory.loc[Inventory["idCode"]== a])
Inventory
#removes the earlier entries
= Inventory.tail(tail)
Inventory
#returns the final inventory list to be used the next day
return Inventory.to_excel("NewInventory.xlsx",sheet_name = "Inventory",engine='xlsxwriter')
"Inventory.xlsx","Today.xlsx") Book_keeping(