I have this code:
test = {"number": ['1555','1666','1777', '1888', '1999'],
"order_amount": ['100.00','200.00','-200.00', '300.00', '-150.00'],
"number_of_refund": ['','','1666', '', '1888']
}
df = pd.DataFrame(test)
Which returns the following dataframe:
number order_amount number_of_refund
0 1555 100.00
1 1666 200.00
2 1777 -200.00 1666
3 1888 300.00
4 1999 -150.00 1888
I want to remove order and order refund entries if:
- "number_of_refund" matches a number from "number" column (there might not be a number of order in the dataframe if order was made last month and refund during the current month)
- amount of "number_of_refund" (which was matched to "number") has a negative amount of "number" amount (in this case number 1666 has 200, and refund of 1666 has -200 so both rows should be removed)
So the result in this case should be:
number order_amount number_of_refund
0 1555 100.00
3 1888 300.00
4 1999 -150.00 1888
How do I check if amount of one column's value is in another column but with opposite amount (negative)?