You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Python基于两个DataFrame设置while循环实现仓库货位分配

仓库货位分配实现方案

需求说明

为需求33托盘的Tito's Vodka分配货位,需遵循以下规则:

  • 优先按Slot_Type_Sequence(5种类型)排序分配
  • 同类型货位内按Label顺序分配
  • 通过while循环实现,凑够总容量为33的前3个货位

数据结构假设

sorted_location DataFrame(示例)

包含货位标签、类型序列、容量信息:

LabelSlot_Type_SequenceCapacity
A01112
A02110
A03111
A04215
.........

demand DataFrame(示例)

ProductPallet_Demand
Tito's Vodka33

代码实现

import pandas as pd

# 加载数据(替换为实际数据加载逻辑)
sorted_location = pd.read_csv("sorted_location.csv")
demand = pd.read_csv("demand.csv")

# 提取目标产品需求
target_product = "Tito's Vodka"
required = demand.loc[demand["Product"] == target_product, "Pallet_Demand"].iloc[0]

# 初始化分配变量
remaining_pallets = required
assigned = []
current_pos = 0

# while循环分配货位
while remaining_pallets > 0 and current_pos < len(sorted_location):
    current_slot = sorted_location.iloc[current_pos]
    # 计算本次可分配托盘数
    assign_num = min(current_slot["Capacity"], remaining_pallets)
    # 记录分配明细
    assigned.append({
        "Product": target_product,
        "Label": current_slot["Label"],
        "Slot_Type_Sequence": current_slot["Slot_Type_Sequence"],
        "Assigned_Pallets": assign_num,
        "Remaining_Pallets": remaining_pallets - assign_num
    })
    # 更新剩余需求和货位指针
    remaining_pallets -= assign_num
    current_pos += 1

# 转换为结果DataFrame
assignment_result = pd.DataFrame(assigned)
print(assignment_result)

期望输出

Product Label  Slot_Type_Sequence  Assigned_Pallets  Remaining_Pallets
0  Tito's Vodka   A01                   1                12                 21
1  Tito's Vodka   A02                   1                10                 11
2  Tito's Vodka   A03                   1                11                  0

内容的提问来源于stack exchange,提问作者Masita

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.22 12:27:12