Deleting rows by comparing some columns in Python

Viewed 35

I have a dataset for 'Client orders' in Python. For some orders, instead of increasing the quantity of an item, there are some duplications.

I want to compare 'Order date' and 'Item Code' for each Client ID, if they are same, I want to delete the duplicated rows and increase Quantity column value by the quantity of deleting rows.

Would you please help me?

Here is the sample:

This is my dataset:

CID Age ItemCode OrderDate Quantity
356 82 WN001 25/08/2020 1
356 82 WN007 25/08/2020 1
356 82 WN007 25/08/2020 1
356 82 WN007 25/08/2020 1
356 82 WN007 05/10/2020 1
357 58 WN009 11/02/2021 1

I want to be like this:

CID Age ItemCode OrderDate Quantity
356 82 WN001 25/08/2020 1
356 82 WN007 25/08/2020 3
356 82 WN007 05/10/2020 1
357 58 WN009 11/02/2021 1

Thanks in advance!

Best, Esra

0 Answers
Related