I got a Dataframe with three columns: "Company", "Cost" and "Refund".
raw_df = pd.DataFrame({
'Company': ['A', 'A', 'B', 'A', 'A'],
'Cost': [10, 10, 10, 0, 158],
'Refund': [0, 0, 0, 10, 0]})
If there has been a refund, then my goal is to remove the corresponding cost. For the above example, the solution would be:
filtered_df = pd.DataFrame({
'Company': ['A', 'B', 'A'],
'Cost': [10, 10, 158],
'Refund': [0, 0, 0]})
How can you code it?
Clarification notes:
- A row can never have a cost and refund. It is always a cost OR a refund
- If there has been a refund, there will ALWAYS be a matching cost with a matching company.
- A single refund cancels only a single cost. Like in the example above.