Competition - motorcycle parts
  • AI Chat
  • Code
  • Report
  • Beta
    Spinner
    # Importing the pandas module
    import pandas as pd
    
    # Reading in the sales data
    df = pd.read_csv('data/sales_data.csv', parse_dates=['date'])
    
    # Take a look at the first datapoints
    df.head()
    df.groupby('warehouse')[['total']].sum()
    import matplotlib.pyplot as plt
    
    avg_units_client_type = df.groupby('client_type')['quantity'].mean()
    avg_units_client_type.plot(kind='barh')
    plt.show()

    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.
    df.head(20)

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

    df.groupby('payment')[['total']].sum()
    df.groupby('product_line')[['unit_price']].mean()
    import matplotlib.pyplot as plt 
    
    fig = plt.figure()
    plt.ylim(0,200000)
    
    plt.yticks(fontsize=20)
    plt.xticks(fontsize=16)
    plt.plot(df.groupby('payment')[['total']].sum(),marker='s', markersize=9, fillstyle='none', linestyle='--', linewidth=2)
    
    import matplotlib.pyplot as plt 
    
    fig = plt.figure()
    plt.ylim(0,100)
    plt.yticks(fontsize=20)
    plt.xticks(rotation=45, fontsize=16)
    plt.plot(df.groupby('product_line')[['unit_price']].mean(),marker='s', markersize=9, fillstyle='none', linestyle='--', linewidth=2)