我有一个名为Transactions的类,具有以下属性。
transactions = ([time_of_day, day_of_month ,week_day, duration, amount, trans_type, location])
这是样本数据类型
time date weekday duration amount type location
0:07 3 thu 2 balance driveup
0:07 3 thu 6 20 withdrawal campusA
0:20 1 tue 2 357 deposit campusB
交易类型是
balance, withdrawal, deposit, advance, transfer
我必须计算不同位置的不同类型交易的数量 这会产生类似的结果
Location | Advance | Balance | Deposit | Transfer | Withdrawal | Total
'driveup'| 4 | 191 | 247 | 28 | 530 | 1000
'campus' | 1 | 2 | 3 | 4 | 5 | 15
结果应该发出一个列表,如下所示:
[['Location', 'Advance', 'Balance', 'Deposit', 'Transfer', 'Withdrawal', 'Total'],
['driveup', 4, 191, 247, 28, 530, 1000],['campus', 1, 2, 3, 4, 5, 15]]
注意:示例数据集和结果列表仅显示1个位置。有3个不同的位置。 'driveup','campusa','campusb'
如何制作清单?
我试过这样的事情
atm_location = list(zip(amounts, transactions, locations))
for element in atm_location
a = element[1] #transactions
b = element[2] #locations
c = element[0] #amounts
if a == 'advance' and b == 'driveup':
drive_advance.append((a,b,c))
和etcetra,所以我基本上只是如果和elifs条件,代码很长所以我不会把它放在这里。