question 191 CSV JSON & JSONL · easy
Average selling price of a stock code
The same product sells at different prices over time. Pricing wants the average price a stock code actually sold for, from an Online Retail II invoice export. Cancellation lines (invoices starting with C) are not sales.
Function
average_price(path, stock_code)Filecolumns
Invoice,StockCode,Description,Quantity,InvoiceDate,Price,Customer ID,CountryReturnsthe mean
Price (a float) over the sale lines whose StockCode equals stock_code exactly, or None when there are noneRulesstock codes are case-sensitive (
85123a is a different product from 85123A); cancellations are ignoredExamples
callaverage_price('lines.csv', '85123A')returns2.6833333333333336
callaverage_price('lines.csv', '71053')returns3.39
callaverage_price('lines.csv', '22423')returnsNone