All problems

Total Revenue

easyPythonMergeAggregation

You're a data analyst at Whetcode Supply, an online shop selling desk gear. The year is closing and the founder is writing the annual summary one part of the range at a time: how much money did this category actually take in? The category under review comes with the request.

No single row holds that answer. The order system was built to stay small, so an order records what was bought and how many — never what it cost. Money lives only in the product catalogue, and so does the label saying which part of the range a product belongs to.

products_df — the catalogue. price is the cost of a single unit.

id name category price
1 Wireless Mouse electronics 25.0
2 Standing Desk furniture 350.0
3 Desk Lamp furniture 40.0
4 Mechanical Keyboard electronics 85.0
5 Notebook Set office 12.0

orders_df — one row per order placed this year.

id customer_id product_id quantity order_date
1 1 1 2 2023-02-01
2 1 4 1 2023-02-01
3 2 2 1 2023-02-10
4 3 3 3 2023-03-05
5 4 5 5 2023-03-11
6 1 3 1 2023-04-02
7 5 1 4 2023-05-20
8 2 5 2 2023-05-22
9 3 4 1 2023-06-01
10 5 2 1 2023-06-15

Input

Both DataFrames above are already built for you — the catalogue and order rows are not read from input. What does arrive is a single line naming the category under review, spelled exactly as the category column spells it.

Task: Print the money the shop took in across every order for products in that category, as a single number rounded to 2 decimals. A category the shop has never sold anything from has taken in nothing, and a total of zero is an answer rather than an error.

Example: if that part of the range had taken in one thousand dollars and fifty cents, you'd print 1000.5.

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…