0

I have a dataframe in Pandas which has data like the below:

charge id charge payment adjustment type
123 $45 $30 0 P
123 $45 0 $10 A
124 $50 $20 0 P

I then use the pivot table to aggregate the data to produce sums / counts of various fields. However summing the charge is incorrect as the same charge can be in the data multiple times. Is it possible to sum the charge once based on the charge id field? So in this example charge id 123 would only be included once in the total.

Shaun
  • 1
  • 1
    Does this answer your question? [Pandas group-by and sum](https://stackoverflow.com/questions/39922986/pandas-group-by-and-sum) – albert May 20 '21 at 06:09
  • Welcome to Stackoverflow. Please take the time to read this post on [how to provide a great pandas example](http://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) as well as how to provide a [minimal, complete, and verifiable example](http://stackoverflow.com/help/mcve) and revise your question accordingly. These tips on [how to ask a good question](http://stackoverflow.com/help/how-to-ask) may also be useful. – jezrael May 20 '21 at 06:10
  • @Shaun, does it work? – top talent May 20 '21 at 06:12
  • I think the main point here is to avoid duplication calculation of the same figure within a group. So the link provided (as an attempt of marking as dup) cannot fully answer the question. – SeaBean May 20 '21 at 06:37
  • Ideally I'd like it to work with the pivot table function and not have to do anything else with the dataframe, so was looking for an option into the pivot table aggregator to handle this. – Shaun May 20 '21 at 11:25

0 Answers0