runtime
198 / 500
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.

Functioncustomer_report(customers_path, orders_path, dest)
customersCSV customer_id,first_name,last_name,email,city,state
ordersCSV order_id,customer_id,status,total; only delivered orders count; orders from customers not in the customers file are ignored
Writesdest 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 orders
Orderby spent, highest first; equal amounts by customer_id ascending
Returnsthe 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

Loading your progress…

A customer spend report from two CSV files — Python practice · Runtime