benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 3d8c2e3e-d823-5f81-bca4-68a3adf883f0

Problem

Answer published by the source. Consult the official source to check your work against its answer.

complete prompt

import pandas as pd
from random import choices, seed

def task_func(products, ratings, weights, random_seed=42):
    """
    Generates a DataFrame containing ratings for a given list of products. Ratings are generated randomly based on the provided weights. 
    The DataFrame is sorted by ratings in descending order.

    Parameters:
    products (list): List of product names.
    ratings (list): List of possible ratings.
    weights (list): List of weights corresponding to each rating for weighted random selection.
    random_seed (int, optional): Seed for random number generation for reproducibility. Defaults to 42.

    Returns:
    pandas.DataFrame: A DataFrame with two columns: 'Product' and 'Rating', sorted by 'Rating' in descending order.

    Requirements:
    - pandas
    - random

    Example:
    >>> products = ["iPhone", "iPad", "Macbook", "Airpods", "Apple Watch"]
    >>> ratings = [1, 2, 3, 4, 5]
    >>> weights = [0.05, 0.1, 0.2, 0.3, 0.35]
    >>> df = task_func(products, ratings, weights, 42)
    >>> print(df.head()) # Expected output is a DataFrame sorted by 'Rating', which may vary due to randomness.
           Product  Rating
    4  Apple Watch       5
    0       iPhone       4
    2      Macbook       3
    3      Airpods       3
    1         iPad       1
    """

instruct prompt

Generates a DataFrame containing ratings for a given list of products. Ratings are generated randomly based on the provided weights. The DataFrame is sorted by ratings in descending order.
The function should output with:
    pandas.DataFrame: A DataFrame with two columns: 'Product' and 'Rating', sorted by 'Rating' in descending order.
You should write self-contained code starting with:

Code

import pandas as pd
from random import choices, seed
def task_func(products, ratings, weights, random_seed=42):

code prompt

Code

import pandas as pd
from random import choices, seed
def task_func(products, ratings, weights, random_seed=42):

entry point

task_func

libs

  • pandas
  • random

Discussion

Discussion

No discussion posts on this page yet. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

See answer Answer published by the source

Artifacts

Code, notes and reproducible work shared by participants. Files are served from a separate origin.

No artifacts on this page yet. Share reproducible code or notes in a contribution. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

Source and history

Official source

initial import