Menu
CoddyTech

Sales Report

Part of the Data and Plots section of Coddy's Machine Learning journey. Lesson 57 of 60.

A furniture shop logged its March orders in sales.csv, one row per order: date, region, product, units, price and cost (both per unit).

Each regional manager wants one chart: profit per product, top earner first. Here is East's:

A bar chart titled Profit in East: five products from the largest profit to the smallest, Desk 414, Chair 408, Lamp 363, Shelf 337.5 and Rug 250

An order's profit is what the shop keeps: the price minus the cost, times the units.

challenge icon

Challenge

Hard

The program reads a region.

  1. Keep that region's orders and add a profit column.
  2. Total the profit per product, largest first.
  3. Print the number of orders, then the top product with its total and its share of the region's profit, as a percent rounded to 1 decimal.
  4. Draw the totals as bars with the fig, ax form, titled Profit in and the region, labelled Product and Profit.

For East, the whole output is below: your two lines, then Coddy's description of your chart.

Orders in East: 13
Most profit in East: Desk (414.0), 23.4% of the region
Charts drawn: 1
Title: Profit in East
X label: Product
Y label: Profit
Bars: 5
Categories: Desk, Chair, Lamp, Shelf, Rug
Heights: [414, 408, 363, 337.5, 250]

Try it yourself

import pandas as pd
import matplotlib.pyplot as plt

region = input()

# Write your code below
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Data and Plots

Practice on your own: Online Python compiler