runtime
413 / 500
question 413 pandas Foundations · easy

Average price per unit sold

A shop wants the average price per unit sold, not per invoice line: a line of 32 boxes at £10.95 counts 32 times. Write average_unit_price(path): read the invoice-lines CSV and return total revenue (Quantity × Price, summed) divided by total units (Quantity, summed). With no units sold, return None.

Functionaverage_unit_price(path)
Filea CSV with Invoice,StockCode,Description,Quantity,Price,Customer ID
Returnsa float, or None when the file has no rows
Examples
callaverage_unit_price('lines.csv')returns7.64811320754717
callaverage_unit_price('two.csv')returns2.7
callaverage_unit_price('boxes.csv')returns10.95

Loading your progress…

Average price per unit sold — Python practice · Runtime