Python-apply(lambda x: )使用

本文详细介绍了Python编程中如何运用apply函数结合lambda表达式对数据进行操作。通过实例解析了lambda函数的创建和apply函数的应用场景,帮助读者理解这两者在数据处理中的作用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值