+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

Python解决了Dataframe中的复杂清单

发布于2021-02-28 16:51     阅读(933)     评论(0)     点赞(23)     收藏(1)


0

1

2

3

4

5

6

在解决订购库存方面需要您的帮助。这只有4个项目,但是实际的DataFrame有10,000个项目。

df = pd.DataFrame(data)

    Inventory count Batch size  Store A needs   Store B needs   Store C needs    Total requires:    Actually requires: 
Buckets         198      20             63               18             104           185                   220
Candy Bars      876     100            567              435             673          1675                  1800
Coke (cans)    1759       6           1212              758             836          2806                  2814
Masks (boxes)  2000    1000            333              444             555          1332                  3000
  • df ['库存盘点']是我手头上有多少库存
  • df ['批量大小']是我每次必须分配的倍数

排水桶我手头上有198个桶。3家商店的总需求为185,但是由于批次大小,导致63-> 80、18-> 20、104-> 120、80 + 20 + 120 =220。我该如何分配库存?

糖果酒吧和可乐的库存均少于df ['实际上需要:'],如何根据需求排名对它们进行分配?

另外,如果有更好的解决方案,我也乐于接受建议

这是数据框: 在此处输入图片描述

请我需要您的帮助,并感谢您的帮助。


解决方案


如果要说的话,您应该搜索分配策略以进行库存和/或供应链管理,如果上述示例过于简单,则意味着需要对此进行限定,这意味着需要更多的商店和/或库存分配策略。

我只是返回一个字典,但是如果您想要或需要的话,可以将数据写回到数据框中的列,或者创建一个新的数据框,或者将数据直接发送到文件中。一切都取决于您需要做什么。

import math

def allocation(x):
    max_units_available = math.floor(x['Inventory count'] / x['Batch size'])
    sa_units_need = math.ceil(x['Store A needs'] / x['Batch size'])
    sb_units_need = math.ceil(x['Store B needs'] / x['Batch size'])
    sc_units_need = math.ceil(x['Store C needs'] / x['Batch size'])

    allocation_needs = [sa_units_need, sb_units_need, sc_units_need]
    # print(allocation_needs)
    # print(max_units_available, tota_untis_need)
    if max_units_available >= sum(allocation_needs):
        return dict(zip(store_list, allocation_needs))
    else:
        #allocation goes in order until all units are allocated
        #you can pass as many allocations strategies as you wish, you just need to code them
        #and work them into your code
        store_list = ['Store A received', 'Store B received', 'Store C received']
        allocation_received = [0]*len(allocation_needs)
        inv_sum = 0

        for i in range(0, len(allocation_needs)):
            inv_sum = inv_sum + allocation_needs[i]
            if max_units_available < inv_sum:
                allocation_received[i] = max_units_available
                break
            else:
                allocation_received[i] = allocation_needs[i]
            max_units_available = max_units_available - allocation_needs[i]
        # print(dict(zip(store_list, allocation_received)))
        return dict(zip(store_list, allocation_received))
    
    df.apply(lambda x: allocation(x), axis=1)

输出:

Buckets            {'Store A received': 4, 'Store B received': 1, 'Store C received': 4}
CandyBars          {'Store A received': 6, 'Store B received': 2, 'Store C received': 0}
Coke(cans)      {'Store A received': 202, 'Store B received': 91, 'Store C received': 0}
Masks(boxes)       {'Store A received': 1, 'Store B received': 1, 'Store C received': 0}

0

1

2

3

4



所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接: https://www.pythonheidong.com/blog/article/863993/0b540417e8e3f209e813/

来源: python黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

23 0
收藏该文
已收藏

评论内容:(最多支持255个字符)