Question: In this task, you are to write a function card _ statistics ( UQ _ card, details ) where UQ _ card ( list of

In this task, you are to write a function card_statistics(UQ_card, details) where UQ_card (list of unique cards) and details (list of list for relevant card details) are output from Task 3. You will calculate the following statistics.
Calculate the absolute timestamp difference for consecutive transactions for each card (for the last transaction you can compare it with the preceding one).
Calculate the minimum, maximum, average and standard deviation of timestamp difference for transactions for each card.
Calculate the average and standard deviation of the amount for each card.
Count how many times the actual and origin places are different for each card (for cards with normal transactions the total count should be lower compared to cards that have malicious transactions).
Finally, card_statistics() function will return three lists: time_dif - a list containing timestamp differences for each transaction, labels a list containing associated label for each transaction in the same order as time_dif (data from the class column in the CSV file) and stats a list containing card specific statistics (8 items per card) in the following, card numbers, average, minimum, maximum and standard deviation of timestamp, average and standard deviation of amount, and count.
The code must pass the following tests:
Test Expected
data = read_data('./CreditCard_2024.csv')
preprocessed_data= card_details(data)
UQ_card, details = unique_card(preprocessed_data)
time_dif, labels, stats = card_statistics(UQ_card, details)
print(stats[0])
[9212146289209856,11121526.7,279718.0,27922487.0,8396427.934176333,118.97,52.98302663222545,9]
data = read_data('./CreditCard_2024.csv')
preprocessed_data= card_details(data)
UQ_card, details = unique_card(preprocessed_data)
time_dif, labels, stats = card_statistics(UQ_card, details)
print(time_dif[0])
12635343.0
sample data from file:
TransactionID TimeStamp CardNumber Transaction_type Type_of_card Entry_mode Amount Actual Origin Class
117102054459212146289209856 EFTPOS Mastercard Magnetic Stripe 78 Warren Warren 0
217228407889212146289209856 EFTPOS AusWide Magnetic Stripe 54 Tibooburra Tibooburra 0
317317729359212146289209856 ATM UniBank NFC 158 Darwin Darwin 0
417261731109212146289209856 Internet AusWide Magnetic Stripe 32 Bairnsdale Bairnsdale 0
517194041229212146289209856 ATM Visa Magnetic Stripe 185 Williams Williams 0
617309325079212146289209856 EFTPOS AusWide Manual 41 Bathurst Bathurst 0
717314940849212146289209856 Internet AusWide NFC 105 Yarrawonga Yarrawonga 0
817105396019212146289209856 EFTPOS UniBank NFC 175 Burnie-Devonport Burnie-Devonport 0
917158509889212146289209856 ATM American Express Chip Card Read 200 Scone Scone 0
1017133473799212146289209856 Internet American Express Magnetic Stripe 185 Bowen Bowen 0
1117340673479212146289209856 EFTPOS Mastercard Magnetic Stripe 106 Bathurst Nowra 0
1217344705809212146289209856 Internet UniBank Manual 200 Tumut Tumut 0
1317172558259212146289209856 EFTPOS American Express NFC 24 Kununurra Kununurra 0
1417355948599212146289209856 ATM AusWide Magnetic Stripe 101 Forbes Forbes 0
1517083627119212146289209856 ATM Discover NFC 128 Esperance Esperance 0
1617123236669212146289209856 ATM American Express Chip Card Read 156 Muswellbrook Muswellbrook 0
1717109985149212146289209856 ATM AusWide Magnetic Stripe 103 Swansea Swansea 0
1817138297859212146289209856 Internet UniBank Manual 92 Dubbo Dubbo 0
1917227549469212146289209856 EFTPOS Discover Magnetic Stripe 115 Toodyay Toodyay 0
2017135116409212146289209856 ATM Mastercard Magnetic Stripe 115 Warracknabeal Warracknabeal 0
2117202438779212146289209856 Internet Mastercard NFC 80 Ulverstone Ulladulla 0
2217172636629212146289209856 EFTPOS Discover Magnetic Stripe 63 Pittsworth Pittsworth 0
2317075260209212146289209856 EFTPOS Mastercard Chip Card Read 175 Gladstone Gladstone 0
2417053041629212146289209856 Internet AusWide Manual 124 Streaky Bay Streaky Bay 0
2517173198349212146289209856 ATM UniBank NFC 172 Shepparton Shepparton 0
2617295631479212146289209856 EFTPOS American Express Magnetic Stripe 126 Emerald Emerald 0
2717047340599212146289209856 ATM American Express NFC 157 Lithgow Lithgow 0
2817115261849212146289209856 EFTPOS Visa Magnetic Stripe 138 Tumby Bay Tumby Bay 0
2917184443029212146289209856 Internet American Express Chip Card Read 144 Bowen Bowen 0
3017084396789212146289209856 ATM ANZ Magnetic Stripe 122 Ballarat Ballarat 0
3117195484669212146289209856 EFTPOS ANZ Manual 137 Geelong Hobart 0
3217157371689212146289209856 Internet Visa Manual 184 Moss Vale Moss Vale 0
3317268198459212146289209856 ATM Visa NFC 48 Bunbury Bunbury 0
3417354435019212146289209856 ATM Visa Chip Card Read 65 Wentworth Wentworth 0
3517127926249212146289209856 ATM AusWide Manual 71 Wallaroo Wallaroo 0
36171066236392121462892098

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!