def items_averages(df):
    """
    Calculate average number of items per session for each user(daily and monthly)
    Args:
        df: Spark DataFrame
    Return:
        daily and monthly averages DataFrame
    """
    daily_items_df = df.groupby('userId','date') \
        .max('itemInSession') \
        .groupBy('userId').avg('max(itemInSession)') \
        .withColumnRenamed('avg(max(itemInSession))', 'avg_daily_items')
    
    monthly_items_df = df.groupby('userId','month') \
        .max('itemInSession') \
        .groupBy('userId').avg('max(itemInSession)') \
        .withColumnRenamed('avg(max(itemInSession))', 'avg_monthly_items')
    
    return daily_items_df.join(monthly_items_df, on='userId')