Competition - motorcycle parts
  • AI Chat
  • Code
  • Report
  • Beta
    Spinner

    Reporting on sales data

    Now let's now move on to the competition and challenge.

    📖 Background

    You work in the accounting department of a company that sells motorcycle parts. The company operates three warehouses in a large metropolitan area.

    You’ve recently learned data manipulation and plotting, and suggest helping your colleague analyze past sales data. Your colleague wants to capture sales by payment method. She also needs to know the average unit price for each product line.

    💾 The data

    The sales data has the following fields:
    • "date" - The date, from June to August 2021.
    • "warehouse" - The company operates three warehouses: North, Central, and West.
    • "client_type" - There are two types of customers: Retail and Wholesale.
    • "product_line" - Type of products purchased.
    • "quantity" - How many items were purchased.
    • "unit_price" - Price per item sold.
    • "total" - Total sale = quantity * unit_price.
    • "payment" - How the client paid: Cash, Credit card, Transfer.

    💪 Challenge

    Create a report to answer your colleague's questions. Include:

    1. What are the total sales for each payment method?
    2. What is the average unit price for each product line?
    3. Create plots to visualize findings for questions 1 and 2.
    4. [Optional] Investigate further (e.g., average purchase value by client type, total purchase value by product line, etc.)
    5. Summarize your findings.

    ✅ Checklist before publishing

    • Rename your workspace to make it descriptive of your work. N.B. you should leave the notebook name as notebook.ipynb.
    • Remove redundant cells like the introduction to data science notebooks, so the workbook is focused on your story.
    • Check that all the cells run without error.
    import pandas as pd
    df = pd.read_csv('data/sales_data.csv', parse_dates=['date'])
    df.head()
    df.groupby('payment')[['total']].mean()
    
    import matplotlib.pyplot as plt
    
    total_sales_for_each_payment_method = df.groupby('payment')['total'].mean()
    total_sales_for_each_payment_method.plot(kind='barh')
    plt.show()
    import pandas as pd
    df = pd.read_csv('data/sales_data.csv', parse_dates=['date'])
    df.head()
    df.groupby('product_line')[['unit_price']].mean()
    import matplotlib.pyplot as plt
    
    average_unit_price_per_each_product_line = df.groupby('product_line')['unit_price'].mean()
    average_unit_price_per_each_product_line.plot(kind='barh')
    plt.show()
    import pandas as pd
    df = pd.read_csv('data/sales_data.csv', parse_dates=['date'])
    df.head()
    df.groupby('client_type')[['total']].mean()
    import matplotlib.pyplot as plt
    
    average_purchase_value_by_client_type = df.groupby('client_type')['total'].mean()
    average_purchase_value_by_client_type.plot(kind='barh')
    plt.show()
    import pandas as pd
    df = pd.read_csv('data/sales_data.csv', parse_dates=['date'])
    df.head()
    df.groupby('product_line')[['total']].mean()
    import matplotlib.pyplot as plt
    
    total_purchase_value_by_product_line = df.groupby('product_line')['total'].mean()
    total_purchase_value_by_product_line.plot(kind='barh')
    plt.show()