• 中心仓与分布式前置仓 库存映射


    import time
    import pandas as pd
    # 聚焦中心仓有货 配属前置仓无货
    data = pd.read_excel('G:/中心仓/center_stock.xlsx')
    print(time.localtime())
    K = data[data['仓库名称'].notna() & data['仓库名称'].str.contains('中心仓') & data['库存数量'].notna() & data['库存数量'] > 0]
    owner = ['信天翁-京东', '白鸥-京东', '信天翁-自采-宠物']
    leimu = ['宠物用品', '运动户外', '母婴用品', '粮油调味', '营养保健', '洗护用品', '日用百货', '家居清洁']
    name = ['破损', '锐澳', '滴露']
    center_stock = K[K['货主'].str.contains('|'.join(owner)) & K['一级分类名称'].str.contains('|'.join(leimu)) & ~(
        K['标品名称'].str.contains('|'.join(name)))]
    
    center_stock.reset_index(drop=True, inplace=True)
    
    # 1.中心仓库存存在一品多货主,先取出center_sp
    center = center_stock.drop_duplicates(subset=['仓库名称', '标品名称', 'sp码'], inplace=False, ignore_index=True)
    center_sp = center.drop(['城市', '长宽高', '毛重', '毛重单位', '库存成本', '货主',
                             '条码', '分类名称', '一级分类名称', 'wms在途数量', 'wms验收中数量', 'wms发货预占库存'], axis=1, inplace=False)
    
    center_sp = center_sp.groupby(['仓库名称', '标品名称', 'sp码']).sum()
    center_sp.reset_index(inplace=True)  # 重设 Multiindex的 index值
    
    # 2.利用中心仓与前置仓之间映射关系,取到前置仓的库存。
    relation = pd.read_excel('G:/中心仓/relation.xlsx')
    # 3.利用 1、2得到中心仓_sp 与映射的前置仓之间的relationship 以及 获取得到中心仓库存
    relation_stock = pd.merge(relation, center_sp, left_on='云仓名称', right_on='仓库名称', how='inner')
    
    # 4.获取前置仓的库存
    a = data['仓库名称'].map(lambda x: pd.notna(x))  # 这里暂时不清楚 为何 通过data[布尔索引]仍然可以得到负数,可以通过库存数量>0的情况
    b = data['库存数量'].map(lambda x: x >=0|pd.isna(x))
    k = data[a & b]  # 去掉无效库存后的库存表
    k[['wms在途数量','wms验收中数量']].fillna(0,inplace=False)
    k = k.assign(zaitu_stock=k['库存数量']+k['wms在途数量']+k['wms验收中数量'])
    stock = k.loc[:, ['仓库名称', 'sp码', 'zaitu_stock']]  # 未包含  'wms在途数量', 'wms验收中数量'
    k = stock.groupby(['仓库名称', 'sp码']).sum()
    k.reset_index(inplace=True)
    
    stock = pd.merge(relation_stock, k, left_on=['前置仓名称', 'sp码'], right_on=['仓库名称', 'sp码'], how='inner',
                     suffixes=('_中心仓', '_前置仓'))
    stock.to_excel('G:/中心仓/中心仓库存分布_1_13.xlsx')
    
  • 相关阅读:
    RPC-Thrift(三)
    RPC-Thrift(二)
    RPC-Thrift(一)
    RPC-整体概念
    Java并发编程--ThreadPoolExecutor
    Java并发编程--Exchanger
    编译libjpeg库
    树莓派3B+ wifi 5G连接
    手动安装 pygame
    摘记 pyinstaller 使用自定义 spec
  • 原文地址:https://www.cnblogs.com/ivan09/p/15979677.html
Copyright © 2020-2023  润新知