有必要按月计算每个用户在每种服务(消息和电话)上花费的金额以及每月花费的资金总额)有关资费限制的信息在 df1 中提供,有关信息df2中的用户自己。如果消息或流量超过资费,那么我们考虑用户为此付出了多少,如果他没有超过限制,那么我们认为成本为0。
df1 = [[50, 4000, 3, 5, tarif1], [1000, 2000, 2, 4, tarif2]]
columns = ['messages_included', 'minutes_included','rub_per_message', 'rub_per_minute', 'tariff_name']
df2 = [[1, tarif1, 5, 20, 100], [1, tarif1, 6, 150, 250], [1, tarif1, 7, 100, 200], [2, tarif1, 5, 45, 10], [2, tarif1, 6, 100, 0], [3, tarif2, 5, 12, 98], [3, tarif2, 6, 10, 6000], [3, tarif2, 7, 800, 2000], [4, tarif2, 5, 80, 10], [4, tarif2, 6, 1000, 500]
columns = ['user_id', 'tariff', 'month', 'total_messages', 'calls_sum']
预期结果,列将添加到 df2,即每月呼叫和消息的成本,以及总成本超过资费的列,包括消息和呼叫的成本。
columns = ['user_id', 'tariff', 'month', 'total_messages', 'calls_sum', 'messages_revenue', 'calls_revenue', 'total_revenue']
决赛桌应如下所示https://imgur.com/a/yvL3mgA
试试这样:
结果:
替代解决方案:
结果: