question 197 CSV JSON & JSONL · medium
Orders per customer, as JSON
The customer-service app shows each customer's orders from a JSON file. Build that file from the orders CSV.
Function
orders_by_customer(src, dest)srcCSV with columns
order_id,customer_id,status,totalWrites
dest: a JSON object from each customer ID to {"orders": [order IDs in file order], "spent": total of those orders}Rulescancelled orders are left out entirely; a customer whose only orders were cancelled doesn't appear;
spent is a numberReturnsthe number of customers written
Examples
callorders_by_customer('orders.csv', '_b0.json')returns4