Skip to content
Project: Analyzing Online Sports Revenue
  • AI Chat
  • Code
  • Report
  • Sports clothing and athleisure attire is a huge industry, worth approximately $193 billion in 2021 with a strong growth forecast over the next decade!

    In this notebook, you will undertake the role of a product analyst for an online sports clothing company. The company is specifically interested in how it can improve revenue. You will dive into product data such as pricing, reviews, descriptions, and ratings, as well as revenue and website traffic, to produce recommendations for its marketing and sales teams.

    You've been provided with five datasets to investigate:

    • info.csv
    • finance.csv
    • reviews.csv
    • traffic.csv
    • brands.csv

    The company has asked you to answer the following questions:

    What is the volume of products and average revenue for Adidas and Nike products based on price quartiles?

    • Label products priced up to quartile one as "Budget", quartile 2 as "Average", quartile 3 as "Expensive", and quartile 4 as "Elite".
    • Store as a pandas DataFrame called adidas_vs_nike containing the following columns: "brand", "price_label", "num_products", and "mean_revenue".

    Do any differences exist between the word count of a product's description and its mean rating?

    • Store the results as a pandas DataFrame called description_lengths containing the following columns: "description_length", "mean_rating", "num_reviews".

    How does the volume of products and median revenue vary between clothing and footwear?

    • Create a pandas DataFrame called product_types containing the following columns: "num_clothing_products", "median_clothing_revenue", "num_footwear_products", "median_footwear_revenue".

    Data preparation

    # Start coding here... 
    import pandas as pd
    
    info = pd.read_csv('info.csv')
    finance = pd.read_csv('finance.csv')
    reviews = pd.read_csv('reviews.csv')
    traffic = pd.read_csv('traffic.csv')
    brands = pd.read_csv('brands.csv')
    
    display(info.head())
    display(finance.head())
    display(reviews.head())
    display(traffic.head())
    display(brands.head())
    # merging dataframes and dropping null values
    df = info.merge(finance).merge(reviews).merge(traffic).merge(brands).dropna()
    
    # display the merged dataframe
    display(df.head())
    # create a new column 'price_category' based on the quartiles of the 'listing_price' column
    df['price_label'] = pd.qcut(df['listing_price'], q=4, labels=['Budget', 'Average', 'Expensive', 'Elite'])
    
    # display the updated dataframe
    display(df.head())

    DataFrame 1: adidas_vs_nike

    # create a grouped dataframe for each price label per brand
    adidas_vs_nike = df.groupby(['brand', 'price_label']).agg(num_products = ('revenue','count'), mean_revenue = ('revenue','mean'))
    
    # round mean, and reset index
    adidas_vs_nike['mean_revenue'] = adidas_vs_nike['mean_revenue'].round(decimals=2)
    adidas_vs_nike = adidas_vs_nike.reset_index()
    
    # print result
    print(adidas_vs_nike)

    DataFrame 2: description_lengths

    # # create description length 
    df['description_length'] = df['description'].str.len()
    
    # # transform description length into bins of 100 words
    df['description_length'] = pd.cut(df['description_length'], bins=[0, 100, 200, 300, 400, 500, 600, 700], labels=['100', '200', '300', '400', '500', '600', '700'])
    
    # # print DataFrame head
    display(df)
    # create description_lengths DataFrame
    description_lengths = df.groupby('description_length').agg(
                                    mean_rating=('rating', 'mean'),
                                    num_reviews=('reviews', 'count')).round(decimals=2)
    
    # reset index
    description_lengths = description_lengths.reset_index()
    
    # display DataFrame
    display(description_lengths)

    DataFrame 3: product_types

    # List of footwear keywords
    mylist = "shoe*|trainer*|foot*"
    
    # Filter for footwear products
    shoes = df[df["description"].str.contains(mylist)]
    
    # Filter for clothing products
    clothing = df[~df.isin(shoes["product_id"])]
    
    # Remove null product_id values from clothing DataFrame
    clothing.dropna(inplace=True)
    # Create product_types DataFrame
    product_types = pd.DataFrame({"num_clothing_products": len(clothing), 
                                  "median_clothing_revenue": clothing["revenue"].median(), 
                                  "num_footwear_products": len(shoes), 
                                  "median_footwear_revenue": shoes["revenue"].median()}, 
                                  index=[0])
    
    display(product_types)