I work in a logistics company and we do B2C deliveries for our client. So we have a rate card in a form of a table and list of deliveries/ transaction, the weight of the package and the location where it was delivered.
I have seen a lot of SUMIFS question being answered here but is very different from the one I need.
1st transaction dataframe contains transaction id, weight, island, category
transaction   weight   island   category
1             0.3      luzon    regular
2             0.5      visayas  express
3             0.5      luzon    express
4             0.4      visayas  regular
5             1.7      visayas  regular
6             1.5      luzon    regular
2nd rate card dataframe  contains category, min_weight,max_weight, fee
category    island  min weight  max weight  fee
regular     luzon     0            0.5       30
regular     luzon     0.51         3.0       40
express     luzon     0            3.0       45
regular     visayas   0            0.5       50
regular     visayas   0.51         3.0       60
express     visayas   0            3.0       65
So i want to calculate for the fee base on the weight of the package and the location. the resulting transaction dataframe should be
transaction      weight      island    category       fee
1                 0.3        luzon      regular        30
2                 0.5       visayas     express        65
3                 0.5        luzon      express        45
4                 0.4       visayas     regular        50
5                 1.7       visayas     regular        60
6                 1.5        luzon      regular        40
So here's the formula in EXCEL on how fees are calculated
=SUMIFS(rate_card.fee, rate_card.min_weight <= transaction.weight, rate_card.max_weight >= transaction.weight, rate_card.island = transaction.island, rate_card.category = transaction.category)
So i want to replicate this particular formula in Python using Pandas
Hopefully someone can provide a solution on my 1 month problem.
 
     
    