以下是配件调拨的Python代码示例:

import pandas as pd

# 读取原始数据
inventory = pd.read_excel('inventory.xlsx', sheet_name='Inventory')
orders = pd.read_excel('inventory.xlsx', sheet_name='Orders')

# 执行调拨操作
for i, row in orders.iterrows():
    # 查找出库物品
    out_item = inventory[(inventory['Product'] == row['Product']) & (inventory['Location'] == row['From'])].iloc[0]
    # 更新出库物品数量
    inventory.loc[out_item.name, 'Quantity'] -= row['Quantity']
    
    # 查找入库物品
    in_item = inventory[(inventory['Product'] == row['Product']) & (inventory['Location'] == row['To'])].iloc[0]
    # 更新入库物品数量
    inventory.loc[in_item.name, 'Quantity'] += row['Quantity']

# 保存更新后的数据
inventory.to_excel('inventory_updated.xlsx', index=False)

本代码使用Pandas库读取原始数据,并使用迭代器遍历订单数据,在循环中查找出库和入库物品,并更新库存。最后,将更新后的库存数据保存到新的Excel文件中。


原文地址: https://www.cveoy.top/t/topic/lMoI 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录