0

I am working with a dataset where I am looking for duplicate charges. In this dataset there are also credit amounts. Id like my final df to show duplicated charges but not to include if there was a credit. If there were (3) of the same charge and only (1) credit I would still like to see the charge once. So far I have a code that shows all duplicate charges. Id like to update it with the above process.

df =



Case| Part_Number | Cost

111 | 2G | 53.00

112 | 7G | 25.00

112 | 7G | 25.00

113 | 8G | 20.00

113 | 8G | -20.00

114 | 9G | 15.00

115 | 2G | 53.00

115 | 2G | 53.00

115 | 2G | -53.00



Charges =



Case| Part_Number | Cost

111 | 2G | 53.00

112 | 7G | 25.00

112 | 7G | 25.00

113 | 8G | 20.00

114 | 9G | 15.00

115 | 2G | 53.00

115 | 2G | 53.00



Credits =

Case| Part_Number | Cost

113 | 8G | -20.00

115 | 2G | -53.00



Id like to remove these 2 credits from the original df and be left with



df =

Case| Part_Number | Cost

111 | 2G | 53.00

112 | 7G | 25.00

112 | 7G | 25.00

114 | 9G | 15.00

115 | 2G | 53.00
Link157
  • 3
  • 1
  • 1
    Hello. Are you basically just dropping duplicates according to the Case column of the first DataFrame? – Steele Farnsworth Dec 30 '21 at 02:26
  • @SteeleFarnsworth Hi, thanks for replying. I dont necessarily want to drop duplicates since I am looking for duplicate charges. So my final output Id like the duplicates but Id remove (1) duplicate if there is a credit line for it. I have created a code that outputs all cases with duplicate charges but some of them have a credit so I would not want to see this instance. But some charges have been done (3) times so if there is only (1) credit Id still like to see (1) of the duplicates. So I cant just remove all case #s that have a credit. – Link157 Dec 30 '21 at 02:37
  • @SteeleFarnsworth I see some similiar questionson on here but most of the examples are how to remove all rows in the original if there is a duplicate value from another dataframe such as this. But I am not looking to remove the case completely if there was only 1 instance of credit in the separate dataframe. So other examples would remove 3 instances of a charge since there is an instance of 1 credit. But I am looking to only remove 1 instance of a charge if so. https://stackoverflow.com/questions/39880627/in-pandas-how-to-delete-rows-from-a-data-frame-based-on-another-data-frame – Link157 Dec 30 '21 at 02:46

0 Answers0