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

Functionaverage_price(path, stock_code)
Filecolumns Invoice,StockCode,Description,Quantity,InvoiceDate,Price,Customer ID,Country
Returnsthe mean Price (a float) over the sale lines whose StockCode equals stock_code exactly, or None when there are none
Rulesstock codes are case-sensitive (85123a is a different product from 85123A); cancellations are ignored
Examples
callaverage_price('lines.csv', '85123A')returns2.6833333333333336
callaverage_price('lines.csv', '71053')returns3.39
callaverage_price('lines.csv', '22423')returnsNone

Loading your progress…

Average selling price of a stock code — Python practice · Runtime