#64MediumFiles & Modules· Working with Tabular Data
Pandas-Style Sales Analysis
Input format
`rows`: a list of CSV lines, the first being the header.
Output format
A dictionary with keys `rows_used`, `rows_dropped` and `by_region`.
Examples
Input: rows = ["region,product,revenue,cost","north,pens,120,70","south,pens,90,40","north,ink,80,100"]
Output: {"rows_used":3,"rows_dropped":0,"by_region":[["south",90,50],["north",200,30]]}
North: revenue 200, profit 50 - 20 = 30. South: revenue 90, profit 50. South ranks first.
Input: rows = ["revenue,cost,region,product","100,,east,tape","abc,10,east,glue","50,20,west,clips"]
Output: {"rows_used":1,"rows_dropped":2,"by_region":[["west",50,30]]}
The columns are in a different order. Two rows have a missing or invalid number and are dropped.
Constraints
- 1 <= len(rows) <= 10^4
- Every data row has as many fields as the header
Study first
- #python
- #csv
- #data-analysis
- #dictionaries
- #sorting
