Optimizing Online Sports Revenue
  • AI Chat
  • Code
  • Report
  • Beta
    Spinner

    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", "count", and "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", "rating", "reviews".

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

    • Store as a pandas DataFrame called product_types containing the following columns: "clothing_products", "clothing_revenue", "footwear_products", "footwear_revenue".

    Completing the project

    • Create a dictionary called revenue_analysis containing the following key-value pairs:
      • "brand_analysis": adidas_vs_nike DataFrame.
      • "description_analysis": description_lengths DataFrame.
      • "product_analysis": product_types DataFrame
    # Start coding here... 
    import pandas as pd
    import numpy as np
    import matplotlib.pyplot as plt
    import matplotlib.patches as mpatches
    import seaborn as sns
    
    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')
    info = info.dropna()
    finance = finance[finance['listing_price'] != 0].dropna()
    reviews = reviews.dropna()
    traffic = traffic.dropna()
    brands = brands.dropna()
    df = pd.merge(info, finance, on='product_id')
    df = pd.merge(df, reviews, on='product_id')
    df = pd.merge(df, traffic, on='product_id')
    df = pd.merge(df, brands, on='product_id')
    df.head(5)
    q1, q2, q3 = df['listing_price'].quantile([0.25, 0.5, 0.75])
    df['price_label'] = pd.cut(df['listing_price'], 
                                bins=[0, q1, q2, q3, float('inf')], 
                                labels=['Budget', 'Average', 'Expensive', 'Elite'])
    
    adidas_vs_nike_df = df.groupby(['brand', 'price_label', 'product_id']) \
                       .agg(num_products=('product_id', 'count'), 
                            revenue=('revenue', 'sum'))
    
    adidas_vs_nike_df.reset_index(inplace=True)
    
    adidas_vs_nike = adidas_vs_nike_df.groupby(['brand', 'price_label']) \
                                        .agg(num_products=('num_products', 'sum'), 
                                             total_revenue=('revenue', 'sum')) \
                                        .reset_index()
    
    adidas_vs_nike['mean_revenue'] = adidas_vs_nike['total_revenue'] / adidas_vs_nike['num_products']
    adidas_vs_nike = adidas_vs_nike[['brand', 'price_label', 'num_products', 'mean_revenue']].round(2)
    
    adidas_vs_nike
    Current Type: Bar
    Current X-axis: price_label
    Current Y-axis: mean_revenue
    Current Color: brand

    Mean Revenue by Brand and Price Label

    Hidden code
    df['description_length'] = df['description'].apply(lambda x: len(x.split()))
    max_length = df['description_length'].max()
    bins = np.arange(0, max_length+100, 100)
    labels = bins[:-1]
    df['word_limit'] = pd.cut(df['description_length'], bins=bins, labels=labels)
    
    description_lengths = df.groupby('word_limit').agg(mean_rating=('rating', 'mean'), num_reviews=('reviews', 'count')).round(2)
                                          
    print(description_lengths)
    chart = df[['rating', 'listing_price', 'brand']]
    
    sns.scatterplot(data=chart, x='listing_price', y='rating', hue='brand')
    
    plt.xlabel('Listing Price')
    plt.ylabel('Rating')
    plt.title('Relationship between Listing Price and Rating')
    
    plt.show()
    df['footwear'] = df['description'].str.contains(
        'foot*|shoe*|trainer*|sneaker*|plimsole*', 
        case=False)
    
    df['clothing'] = ~df['footwear'].isin(df['footwear']).dropna()
    
    product_types = pd.DataFrame({
        'num_clothing_products': len(df['clothing']),
        'median_clothing_revenue': df['clothing'].median(),
        'num_footwear_products': len(df['footwear']),
        'median_footwear_revenue': df['footwear'].median()
    }, index=[0])
    # Share your results in this format
    revenue_analysis = {"brand_analysis": adidas_vs_nike,
                        "description_analysis": description_lengths,
                        "product_analysis": product_types}
    
    # Call the answer!
    revenue_analysis