question 198 CSV JSON & JSONL · hard
A customer spend report from two CSV files
Marketing wants every customer with how many orders they received and how much they spent, biggest spenders first. Join the customers file with the orders file and write the report.
Function
customer_report(customers_path, orders_path, dest)customersCSV
customer_id,first_name,last_name,email,city,stateordersCSV
order_id,customer_id,status,total; only delivered orders count; orders from customers not in the customers file are ignoredWrites
dest with header customer_id,name,orders,spent: name is "First Last", spent has two decimals; every customer appears, with 0 and 0.00 if they had no delivered ordersOrderby
spent, highest first; equal amounts by customer_id ascendingReturnsthe number of customers written
Examples
callcustomer_report('customers.csv', 'orders.csv', '_q0.csv')returns4
callcustomer_report('one_customer.csv', 'orders.csv', '_q01.csv')returns1
callcustomer_report('no_customers.csv', 'orders.csv', '_q02.csv')returns0