Python-apply(lambda x: )使用

def instant_order_deal(plat, special_product, clearance_goods, new_product_instant,orders):
    """
    :param plat: 要计算的平台
    :param special_product: 特定库龄产品,其他平台的,amazon的在下面单独读取
    :param clearance_goods: 清仓产品
    :param new_product: 新品
    :param orders: 订单
    :return:
    """
    # 退款订单处理
    orders['订单总金额(包含客户运费、平台补贴)'] = orders.apply(lambda x: 0 if (x['订单类型'] == 'refund') else x['订单总金额(包含客户运费、平台补贴)'], axis=1)
    "中间特定sku处理毛利"
    # orders['毛利'] = orders.apply(lambda x: (x['平均采购价']* 0.4 + x['毛利']) if (x['产品代码'] == 'S4338867210')| (x['产品代码']=='S2130010010') else x['毛利'],axis=1)
    orders['毛利'] = orders.apply(lambda x: (x['毛利'] + 5) if (x['产品代码'] == 'S1416028410') | (x['产品代码'] == 'S1416028440') | (x['产品代码'] == 'S1416028470')  else x['毛利'], axis=1)
    """折价商品毛利计算 + 额温枪"""
    depreciate = read_data().read_depreciate()
    orders['毛利'] = orders.apply(lambda x: (x['平均采购价'] * 0.4 * x['数量']  + x['毛利']) if (x['产品代码'] in depreciate) and x['订单类型'] == 'sale' else x['毛利'],axis=1)


    orders['平均采购价'] = orders.apply(lambda x: 0 if (x['订单类型'] == 'resend') else x['平均采购价'], axis=1)
    # 中英仓处理
    orders['仓库分类'] = orders.apply(lambda x: '中仓' if (x['发运仓库'] =='SH [上海奉贤仓]') | (x['发运仓库'] =='WZC [温州仓]') | (x['发运仓库'] =='SZC [深圳仓]') else '海外仓', axis=1)
    # 处理新品
    # if plat == 'ebay' or plat == 'shopee' or plat == 'amazon' :
    newproduct = read_data().read_newproduct()
    orders['仓库分类'] = orders.apply(lambda x: '新品' if (x['产品代码'] in newproduct) else x['仓库分类'], axis=1)

    #处理海运产品
    shipping = read_data().read_shipping()
    orders['仓库分类'] =orders.apply(lambda x: '海运产品' if(x['产品代码'] in shipping  and  x['仓库分类'] != '海外仓') else x['仓库分类'],axis=1)

    # 当月转清仓处理
    orders['仓库分类'] = orders.apply(lambda x: '特定库龄'if isClearance(x['付款时间'], x['产品代码'], clearance_goods) != None  else x['仓库分类'], axis=1)

    # 特定库龄处理
    orders['仓库分类'] = orders.apply(lambda x: '特定库龄' if (x['发运仓库'] == 'GSE [古斯美东仓]' and x['平台']!='ebay') else x['仓库分类'], axis=1)
    if plat == 'amazon':
        # amazon的特定库龄需要单独读取
        special_product_a = read_data().read_special_product(plat)
        special_product_as = read_data().read_special_product('amazon特殊')

        orders['仓库分类'] = orders.apply(lambda x: '特定库龄' if (x['产品代码'] in special_product_as) else x['仓库分类'], axis=1)
        orders['仓库分类'] = orders.apply(lambda x: '特定库龄' if ((x['发运仓库'] + x['产品代码']) in special_product_a) else x['仓库分类'], axis=1)

    else:
        special_product = read_data().read_special_product('其他平台')
        orders['仓库分类'] = orders.apply(lambda x: '特定库龄' if (x['产品代码'] in special_product) else x['仓库分类'], axis=1)
        orders['仓库分类']=orders.apply(lambda x:'稳定期' if (x['仓库分类']=='中仓')| (x['仓库分类']=='海外仓' )else x['仓库分类'],axis=1 )
    # 处理好仓库分类,接下来判断是否是开发新品
    orders = pd.merge(orders, new_product_instant, on='产品代码', how='left')
    orders['开发新品'] = orders['开发新品'].fillna('非开发新品')
    # 然后处理货值
    orders['货值'] = orders['数量'] * orders['平均采购价']

    # orders = pd.merge(orders,mask_instant, on='产品代码', how='left')
    # orders['口罩'] = orders['口罩'].fillna('非口罩')

    return orders
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值