I am trying to format some data from an external source and make some sorting and groupings. Below is the snippet that I am using currently. I am trying to make the sorting and grouping work.
pmtAccount = []
pmtAmount = []
for payment in payments_sent:
print ("{} {:>15}".format(payment['to'], payment['amount']))
pmtAmount.append(payment['amount'])
pmtAccount.append(payment['to'])
#-- Attempt to summarize output
df = pd.DataFrame(list(zip(pmtAccount, pmtAmount)), columns =['To', 'Amount'])
result = df.groupby('To')['Amount'].agg(['count','sum']).reset_index()
result['count'] = result['count'].astype(str) + ' Transactions'
print(result)
Current Output:
#-- Output of the line print ("{} {:>15}".format(payment['to'], payment['amount']))
199SJFW1K 100.0000000
ABC123ABC 100.0000000
ABC123ABC 50.0000000
ABC123ABC 300.0000000
123ABC123 200.0000000
123ABC123 50.0000000
123ABC123 100.0000000
ABC123ABC 300.0000000
ABC123ABC 250.0000000
XYXY12XYX 250.0000000
XYXY12XYX 500.0000000
1OPR12DRT 41.0000000
KSJDHW812 0.1900000
#--
To count sum
0 ABC123ABC ... 5 Transactions 100.0000000 50.0000000 300.0000000 300.0000000250...
1 XYXY12XYX ... 2 Transactions 250.0000000500.0000000
2 KSJDHW812 ... 1 Transactions 0.1900000
3 1OPR12DRT ... 1 Transactions 41.0000000
4 123ABC123 ... 3 Transactions 200.000000050.0000000100.0000000
5 199SJFW1K ... 1 Transactions 100.0000000
Needed Output: #-- Sorted and grouped
0 ABC123ABC ... 5 Transactions 1,100.0000000 #-- Sum of (100.0000000, 50.0000000, 300.0000000, 300.0000000, 250.0000000)
1 123ABC123 ... 3 Transactions 350.0000000
2 XYXY12XYX ... 2 Transactions 750.0000000
3 1OPR12DRT ... 1 Transactions 41.0000000
4 199SJFW1K ... 1 Transactions 100.0000000
5 KSJDHW812 ... 1 Transactions 0.1900000
Total Transactions: 13 Total Amount: 2,341.19