I am trying to replicate SUMIFs in Python that I have in my excel by creating a new column called SumifsZ. SumifsZ is the desired output i would need in python.
my formula in first row of SumifsZ column is =SUMIFS(C:C,B:B,"Z",A:A,A2) , i would need that to be replicated in 3rd,4th rows.... etc.
Product | Region | QTY | SumifZ |
---|---|---|---|
A | X | 3 | 13 |
A | Z | 3 | 13 |
B | Z | 9 | 9 |
B | X | 2 | 9 |
C | Y | 5 | 0 |
A | Z | 10 | 13 |
D | Z | 11 | 20 |
D | Z | 9 | 20 |
E | Y | 6 | 0 |
F | Z | 7 | 7 |
the code i am using is Data['SumifsZ'] = Data.query('Region =="Z"').QTY.sum()
and i am not getting the same result as excel. please help!