Motorcycle Parts-Sales Data Analysis
  • 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.
    # Importing the pandas module
    import pandas as pd
    
    # Reading in the sales data
    df = pd.read_csv('data/sales_data.csv', parse_dates=['date'])
    df.head()

    💪 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.

    ⌛️ Time is ticking. Good luck!

    Data Understanding:

    1. Check the data for any missing value
    2. Check the shape of the dataset
    3. Check if any rows are duplicated?
    print(df.isna().sum())
    print(df.shape)
    print(df.duplicated().sum())

    Total Sale vs Payment Method

    What are the total sales for each payment method?

    # Importing the plt module
    import matplotlib.pyplot as plt
    # Group the sales by payment method and compute the sum total for each payment method
    total_sales_payment = df.groupby("payment")[["total"]].sum()
    print(total_sales_payment)
    total_sales_payment.plot(kind='bar')
    plt.show()
    FINDINGS

    The payment method for maxium total sale is "Transfer" whereas "Cash" is the least chosen payment method.

    Average Unit Price vs Product_Line:

    What is the average unit price for each product line?

    avg_unit_price_product = df.groupby("product_line")[["unit_price"]].mean()
    print(avg_unit_price_product)
    avg_unit_price_product.plot(kind = 'bar')
    plt.show()
    FINDINGS

    The average unit_price for the product "Engine" is maximum and the product "Frame & body" has the second maxiumum unit price.

    Average Unit Price vs Product_Line and Client_Type

    What is the average unit price for each product for different clients?