I am trying to do a simple thing on dataframe, but I am getting output differently than I expected.
These are parameters and it's values I am getting from called function:
context : ['documentNo']
aggOperation : sum
aggColumn : amount
comNewColName : totalAmountCollected
Result type : <class 'pandas.core.frame.DataFrame'>
Index(['Result Columns :\ndocumentNo', 'Result Columns :\ntotalAmountCollected'], dtype='object')
Result I am getting:
documentNo totalAmountCollected
0 200002692 8,260 1,132,210 80,536 40,120 14,160 1,6...
1 200002699 711,093 (711,093)
2 200002700 (968) 968
3 200002764 5,310 62,304 61,124 14,603 75,190 62,658...
4 200002765 10,620 (10,620)
My groupby code is this:
df = sourceDF.groupby(context)[aggColumn].agg(aggOperation).reset_index().rename(columns={'amount':comNewColName})
I have to get
documentNo totalAmountCollected
0 200002692 978979
1 200002699 897897
2 200002700 968
3 200002764 877899
4 200002765 10,620
How can I correct my code?